Working alone has its own share of challenges. You are expected to master anything out there in the wild.
So, this time I was asked to enable batch processing of emails for an existing phplist installation. Well, I hadn’t managed a phplist installation before, and so the task looked a bit daunting on the onset (which was not to be, as I figured out later).
Kindly enough, I was also provided a couple of links (this and this) to start from. The second of these (from phplist forums) looked promising as it provided step-by-step instructions for the purpose. However, it did not work for me (and I think rightly so, because the steps are more than 5 years old, and phplist should have changed considerably in the interim).
So, I decided to dissect the code itself to find out how to go with it. I was able to establish processqueue.php (in admin folder) and config.php (in config folder) as the two files that were of interest in this context.
Analyzing the code in processqueue.php together with some excellent commenting in config.php helped me zero-in on MAILQUEUE_BATCH_SIZE and MAILQUEUE_BATCH_PERIOD as the only 2 options that needed tweaking.
So, in my case, I needed to restrict emails to no more than 450 emails per day, and the mathematics worked out to be 3 emails per 10 minutes approximately.
So, MAILQUEUE_BATCH_SIZE was set to 3, and MAILQUEUE_BATCH_PERIOD to 580:
# define the amount of emails you want to send per period. If 0, batch processing # is disabled and messages are sent out as fast as possible define("MAILQUEUE_BATCH_SIZE",3); # define the length of one batch processing period, in seconds (3600 is an hour) define("MAILQUEUE_BATCH_PERIOD",580);
A very important thing to notice here is that batch period is set to a bit less than 600 seconds (60*10). This ensures that cron jobs firing at regular intervals always make the emails to be sent at those intervals overcoming minor timing issues.
The last step was to configure a cron job to invoke the processqueue.php script at 10 minute intervals. Here’s the cron tab entry for that:
*/10 * * * * /usr/local/bin/curl 'http://www.domain.com/phplist/admin/index.php?page=processqueue&login=adminuser&password=adminpass'
And since then, we have been receiving emails as configured, hats off to phplist team for such useful and friendly mailing list (although I wish these settings were configurable from admin interface itself, without needing to manipulate php code).
As a side-note, you can also enable throttling to ensure that emails are sent at intervals or uniformly over the batch period, to avoid overloading the server at once. There’s this comment in the config.php related to throttling:
# Throttle sending messages; indicates the number of milliseconds to pause # between each message (millisecond is one-millionth of a second) define("MAILQUEUE_PROCESSING_THROTTLE",2000000);
And I was confused whether I have got my basic mathematics wrong. It was also mentioned that the above would send emails at 2 second intervals.
And I was like, isn’t a millisecond one-thousandth of a second. And wouldn’t this send emails at a minimum of 2000 second intervals.
The answer again lied with processqueue.php. First of all, this value is 2 seconds because it’s in microseconds (and not milliseconds). Secondly, I doubt if this option has any effect on sending messages at all, because I could not find any reference to it in processqueue.php. However, another property in config.php called MAILQUEUE_THROTTLE defined as follows:
# to avoid overloading the server that sends your email, you can add a little delay # between messages that will spread the load of sending # you will need to find a good value for your own server # value is in seconds (or you can play with the autothrottle below) define('MAILQUEUE_THROTTLE',0);
was being used and the value of this property was used for specifying the sleep interval between 2 mails, so I think this is the property you should look out for manual throttling (you also have an option for auto throttling which spreads out your messages uniformly in the batch processing period).