0

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...

tim
  • 9,896
  • 20
  • 81
  • 137
  • 1
    Curious that it so very slow. Writing directly to the database table would be easy - and fast. Make sure to write to both the `_bp_messages_recipients` and `_bp_messages_messages ` tables. – shanebp Aug 07 '23 at 15:24
  • 1
    If you don't need to personalize the message, have you considered a site-wide notice? `...wp-admin/admin.php?page=bp-notices` – shanebp Aug 07 '23 at 18:46
  • Hi @shanebp Yeah unfortunately I wanna make it personal! I was also wondering about the awful performance - first I really did think it's only because of the mails being sent (for me: using a 3rd party mail service -> a lot of API calls necessary!) - but no, I was wrong... Can you imagine or see from the code whick hook or actions makes this so incredibly slow? – tim Aug 12 '23 at 06:00

0 Answers0