MyBB Community Forums

Full Version: Can anyone give insight into "run_shutdown" and "send_mail_queue"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am running 1.8.14 on a site for an HOA. we have a small number (60) of users, relatively low traffic with maybe 0-3 posts per day.  When there is a post people want to be notified so everyone is configured to receive instant email notification for any post.  I do have expertise in PHP so I am capable of making modifications to the code where needed, but even with expertise understanding all the intracacies of the code can be a challenge at times.  I am asking for help in understanding what is going on with run_shutdown and delivery of queued email notifications.

The problem I am trying to address is someone posting something, but then nobody getting "instant" email notifications until many hours later. From what I can tell there is a cron job created to deleivery "mass mail" regularly but that does not effect email notifications.  Email notifications only occur is someone accesses the site and does something that triggers the execution of send_mail_queue .

I added debugging statements and confirmed that almost anytime a new page is accessed, add_shutdown is executed to add send_mail_queue to the array of functions that execute when run_shutdown  executes.  I added a call to my_mail at the top of run_shutdown to send me an email everytime run_shutdown executes (this was done on a experimental site that I was the only one using -- I created 3 test accounts total, so it did not generate many emails). Those emails told me I could login to the website and go to a few links, but although run_shutdown would execute multiple times during those experiments, in many if not all cases, it was called WITHOUT send_mail_queue in the list of functions to execute.  I do not understand how that could be because it seems with every new page I accessed, send_mail_queue was being added to the list of functions run_shutdown would execute. this was an issue because even with me logging in AFTER I had generated a post, send_mail_queue was not executing and notifications were languishing in the queue.

Does anyone have any better insight into what is going on here? I am VERY hesitant to mess with any of the admin php code, but anyone have insight into modifying the code associated with mass mail (which runs periodically) to also have it send the email notifications?
send_mail_queue() is added to the list of shutdown functions in init.php, so it should be in the list for every user accessible page.

One thing that I've done in the past is add a task to process the mail queue calling send_mail_queue() periodically for bigger boards with lots of emails: https://community.mybb.com/thread-167827...pid1147562

There have been other reports about delayed email sending (see the above linked thread), but I've never managed to track down a concrete reason for it. One of the things I'm hoping to do as part of 1.9.0 is to improve the mail system - I'll probably look and see if we can improve how the mail queue works at the same time, and hopefully improve our logging of sent mails.