I want to implement an admin-feature to send a direct PM to every user of my Buddypress plattform on specific occasions.
I found the PHP function messages_message_sent
already which works great when used like so:
$msg = array(
'recipients' => [$uid],
'content' => $content
);
messages_new_message ($msg);
This is insanely slow - I guess because it actives so many hooks and actions in the system. First I thought the mail notification would cause the delay so I deactivated it:
remove_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
Unfortunately, still I can only send 40 PMs in 1min PHP execution time (on a dedicated 24-cores CPU) - not sure what exactly is causing this delay but it's insane.
Anyone can help and tell me what hooks are irrelevant and/or trigger all that stuff?
I'm now thinking about directly writing in the messages-table in the database directly...