larger smaller normal text version of this page
Phplist Documentation Message functions Process the message queue Setting up cron jobs

Cron Job Examples


This page provides some examples of cron jobs applied by Phplist users. You are welcome to add your own cron job. Please include a brief description of what the cron job does, and add your settings for MAILQUEUE_BATCH_SIZE, MAILQUEUE_THROTTLE , etc. in the header of the crontab file. Also include whether your server is running PHP-cli or PHP-cgi .

Cron job for shared hosting.
I couldn't get the CLI version to work so I worked around it. Here is what I wanted:
1) No overwhelm the shared host email server (500 messages/hr)
2) Emails to go out soon after user clicks send
3) No worry about php timeouts
4) Work with email server with self-signed SSL certificate.

Every 10 minutes, do this:
#=================================================================
# Run in CGI Mode.  CGI mode didn't work for me with these turned off.
define ("MANUALLY_PROCESS_BOUNCES",1);
define ("MANUALLY_PROCESS_QUEUE",1);    
# Using a self-signed cert for mail server.
$bounce_mailbox_port = "110/pop3/novalidate-cert";  
# Email batch settings
define("MAILQUEUE_BATCH_SIZE",80);     # 80 emails every 10 minutes = 480 emails/hr
define("MAILQUEUE_BATCH_PERIOD",590);  # 10 minutes
define('MAILQUEUE_THROTTLE',1);        # Batch run length:  min 80 seconds/max PHP Timeout - check max_execution_time in php.ini
# Don't look like a spammer.
define('USE_DOMAIN_THROTTLE',1);  
define('DOMAIN_AUTO_THROTTLE',1);  
# Don't forget!
define("MAXLIST",20);
define ("TEST",0);
#=================================================================
#====  Cronjob setup ====
*/10 * * * * lynx -dump 'http://www.domain.org/apps/phplist/admin/index.php?page=processqueue&login=admin&password=mypassword' > phplist.processqueue.html
35 * * * * lynx -dump 'http://www.domain.org/apps/phplist/admin/index.php?page=processbounces&login=admin&password=mypassword' > phplist.processbounces.html
#=================================================================



Cron job for large list without limits of msgs/hr (PHP-cli)

#=================================================================
#      MY CRON JOB FOR PHP-CLI
# crontab for processing all messages with status 'queued' with PHP-cli
# - MAILQUEUE_BATCH_SIZE=0 is recommended.
# - MAILQUEUE_BATCH_PERIOD irrelevant as batch size is disabled
# - Setting the MAILQUEUE_THROTTLE may be needed to avoid overloading the server.
# All emails will be sent in one run.
# Processing starts at 17 min after midnight and continues as long as
# subscribers have to be processed. This may take many hours with large lists.
# Second job starts precisely at high noon.
# Setting up multiple entries at different hours will repeat the process queue command multiple
# times a day.
# Make sure that enough time has passed and that the previous job has finished
# before scheduling the next.
#=================================================================
17 0 * * * USER=listprocessor; export USER; /usr/bin/php /home/mydomain/public_html/phpList/admin/index.php -pprocessqueue -c/home/mydomain/public_html/phpList/config/config.php >/dev/null
00 12 * * * USER=listprocessor; export USER; /usr/bin/php /home/mydomain/public_html/phpList/admin/index.php -pprocessqueue -c/home/mydomain/public_html/phpList/config/config.php >/dev/null

Source: Forum post by jotazzu


Cron job for command line script (PHP-cli)

#=================================================================
# CRON JOB FOR RUNNING THE COMMAND LINE SCRIPT "PHPLIST" - FOR PHP-cli
#
# - MAILQUEUE_BATCH_SIZE=???
# - MAILQUEUE_BATCH_PERIOD=???
# - MAILQUEUE_THROTTLE=???
#=================================================================
*/15 17-23 * * 2,3,4,5,6 /sbin/phplist -pprocessqueue
*/15 0 * * 2,3,4,5,6 /sbin/phplist -pprocessqueue
*/15 1-6 * * 2,4,6 /sbin/phplist -pprocessqueue
10 1 * * 3,5,7 /sbin/phplist -pprocessbounces

This is how I've set up my scripts to fire. We have a large list of users with many (300+) lists so it's important the script fires often.
  • Basically the first line says I want the script to run every 15 minutes starting at 5 p.m. (17) and running through 11:00 p.m. (23). This should happen Mon. (2) through Fri. (6).
  • Second line does the same thing over, except runs it at midnight as well (0). (as an aside, this means it will run at 12:00, 12:15, 12:30 and 12:45.)
  • The third line sets the script to run from 1 a.m. to 6 a.m. (every 15 minutes) only on Mon., Wed., and Fri.
  • The last line is for processing bounces. I run it starting at 1 a.m. Tue., Thu., and Sat.
  • One note about cron and your system. It's entirely dependant on your setup and distro what the actual syntax of the commands may be. Find out what you're running for cron, and then enter the commands above with any changes that may need to be made. (source: Forum post by sterlinged)


Cron job running the Lynx text browser (PHP-cgi)

#=================================================================
# CRON JOB FOR RUNNING THE LYNX TEXT BROWSER - FOR PHP-cgi
# My config.php file has:
# - $commandline_users = array("root","LIST_USER","admin","SERVER_ACCOUNT");
# - define("MAILQUEUE_BATCH_SIZE",200);
# - define("MAILQUEUE_BATCH_PERIOD",3300);
# - define('MAILQUEUE_THROTTLE',4);
#=================================================================
0 * * * * lynx -dump 'http://www.domain.com/lists/admin/index.php?page=processqueue&login=LIST_USER&password=PASSWORD' > /dev/null
30 * * * * lynx -dump 'http://www.domain.com/lists/admin/index.php?page=processbounces&login=LIST_USER&password=PASSWORD' > /dev/null

My server is a cli version of php. However, I appear only to get this to work using the lynx command.
I have a small list but to ensure I don't have server issues, I have batched this to relatively small amounts. Ensure that the batch period is LESS THAN the time between running your cron process. In my case, my cron runs every 1hr (3600 secs).
  • The first line will process any pending emails at start of every hour.
  • The second line will process any bounced emails sent to our bounce email mailbox 30 minutes past every hour. Source: Forum post by Telfie


Cron job for command line script (PHP-cli)

#=================================================================
# CRON JOB FOR COMMAND LINE SCRIPT (PHP-cli)
# My config.php file has:
#   $commandline_users = array("user1","user2","user3");
#   define("MAILQUEUE_BATCH_SIZE",200);
#   I use the MAILQUEUE_PROCESSING_THROTTLE hack by jotazzu ( http://forums.phplist.com/viewtopic.php?t=2142 )
#
#
#   define('USE_DOMAIN_THROTTLE',1);
#   define('DOMAIN_BATCH_SIZE',1);
#   define('DOMAIN_BATCH_PERIOD',120);
#=================================================================
15,30,45,00 * * * * /var/www/www.domain.com/phplist phplist-2.10.2/bin/phplist -p processqueue > /dev/null

Since I have a lot of users in aol, hotmail, yahoo, etc, each subsequent run after the first sends out maybe 20-40 emails. This is why I have the cron job run so frequently. The first run will take several hours to run. During this time, subsequent calls to phplist -p processqueue should exit with the above output, until the first batch (most non-yahoo/hotmail accounts) are sent out. Subsequent batches send a few emails (20-30 emails) out every 15 minutes. source: Forum post by mp459


Cron job for command line script (PHP-cli)

#=================================================================
# CRON JOB FOR COMMAND LINE SCRIPT (PHP-cli)
# My config.php file has:
#   $commandline_users = array("listprocessor","any other","users,"you want","to set");
#   define("MAILQUEUE_BATCH_SIZE",200);
#   define("MAILQUEUE_BATCH_PERIOD",3600);
#   define('MAILQUEUE_THROTTLE',5);
#
#  Every hour at 15 minutes past, we process the queued messages
#=================================================================
15 * * * * /usr/local/scripts/phplist -p processqueue


This will send a message every 5 seconds, batching no more than 200 message per hour. This is fine for us as we have 800+ subscribers and two lists. Source: Forum post by Cafamily.


Cron job with batch processing (PHP-cgi)

#=================================================================
# CRON JOB with batch mode on - (PHP-cgi)
# crontab for processing all messages with status 'queued' or 'inprocess'.
# Processing starts at 17 min after midnight and continues for 3 hours with
# a reload after one hour. The hour of the cron schedule as well as the
# reload count has to be increased by 1 for each crontab entry.
# Maximal MAILQUEUE_BATCH_SIZE * NUMBER_OF_CONTRAB_ENTRIES emails will be send.
# In this example is NUMBER_OF_CRONTAB_ENTRIES=4.
#=================================================================
17 0 * * *   wget -q -O - 'http://www.mydomain.com/lists/admin/index.php?page=processqueue&login=myusername&password=mypassword&reload=0' >/dev/null
17 1 * * *   wget -q -O - 'http://www.mydomain.com/lists/admin/index.php?page=processqueue&login=myusername&password=mypassword&reload=1' >/dev/null
17 2 * * *   wget -q -O - 'http://www.mydomain.com/lists/admin/index.php?page=processqueue&login=myusername&password=mypassword&reload=2' >/dev/null
17 3 * * *   wget -q -O - 'http://www.mydomain.com/lists/admin/index.php?page=processqueue&login=myusername&password=mypassword&reload=3' >/dev/null

This cron job uses wget and therefore you have to set one entry for each increasing reload. The number of entries multiplied with MAILQUEUE_BATCH_SIZE must be higher than the number of subscribers to that list (assuming the message will be send only to one list). You have to add additional entries when the list grows. To calculate the time between the schedules see at how to tune MAILQUEUE_BATCH_SIZE. (Each schedule has to be in one line.)
Source: Forum post by jotazzu


Cron job without batch processing (PHP-cgi)

#=================================================================
# CRON JOB with batch mode off - (PHP-cgi)
# crontab for processing all messages with status 'queued' or 'inprocess'.
# A schedule is executed every 20 minutes at every day.
# Batch mode is assumed to be off
# Trottling is assumed to be zero.
#=================================================================
*/20 * * * *   wget -q -O - 'http://www.mydomain.com/lists/admin/index.php?page=processqueue&login=myusername&password=mypassword' >/dev/null

In some cases it is possible to avoid lengthy calculations. If, for example, throttling is set to zero and a schedule shall be executed multiple times at every day, you may write it simply as one line because the increasing 'reload' parameter is not needed. This kind of cron table does not need a calculation of "the amount of emails send with one call/schedule" because there is always another schedule following and the minimal time between two schedules is simply 1200s (upper limit of the real runtime of the script). You only have to take care that the message is completely processd before the next is queued. (Each schedule has to be in one line.)
For very big lists (100,000+ subscriber) thise last example is probably the best way to do the job if not using the "CLI version of PHP".
Source: Forum post by jotazzu


Process the queue on PHP-cgi through a PHP script v.2

This is a combination of Running a cron job on PHP-cgi through a PHP script and Process the queue on PHP-cgi through a PHP script. I was setting up phplist on Netfirms for someone, and they have security settings which didn't allow the other options.

First, you'll have to create a file called phplist_cron.php in the /lists directory with the following code (make sure to change what's in ALL CAPS):

<?php
function process_queue() {
//variables
$url = "http://www.DOMAIN.COM/lists/admin/?page=processqueue&login=USERNAME&password=PASSWORD";

//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);

//clean up
curl_close($ch);

return $result;
}
$result = process_queue();
?>


Then, use the following command for the cron job and set the frequency as desired:

/usr/local/nf/php5/bin/php -f ./DOMAIN.COM/lists/phplist_cron.php


Source: Julianna

Tips & tricks from the forum


Running a cron job on PHP-cgi through a PHP script
my host has disabled wget, get and lynx and the server i am on is setup in cgi not cli. so i created a php file in my userspace that calls the process queue page (with the login credentials) like this:

#!/usr/local/bin/php
<?php
  include('http://www.domain.com/lists/admin/?page=processqueue&login=USERNAME&password=PASSWORD');
?>

This file must have 755 permissions so it can be executed.

Then all i did was set up a cron job to run this file like this:

/home/domain/public_html/lists/admin/pq.php

This does mean that you must enable manual queue processing in the config.php file, like this define ("MANUALLY_PROCESS_QUEUE",1); as essentially it is still being processed manually but the cron is doing the donkey work. Just keep in mind to avoid clicking on the process queue link, while a cron job process is running.
P.S.: only took me 8 hours to figure out that the normal cron setup would not work!!! be warned!
Source: forum post by wilfy


Process the queue on PHP-cgi through a PHP script
My host is running PHP as a CGI, and only allows 200 e-mails per hour, so I cap phpList at roughly 150 per hour with the following batch (cron processes the queue every 15 minutes):
define("MAILQUEUE_BATCH_SIZE",38);
define("MAILQUEUE_BATCH_PERIOD",900);
define('MAILQUEUE_THROTTLE',6);
I may readjust these to send a single batch of 150 message once per hour, but have to test it first to make sure the script does not exceed time limits when doing so. Until then, I'll stick with the smaller batches.

I went through all of the posted cron examples with no success. As far as cron is concerned. The standard example below doesn't work for me because the login info doesn't get passed to the script:

/bin/usr/php /home/domain.com/lists/admin/index.php page=processqueue login=myusername password=mypassword >/dev/null

The other examples don't work for me, either, because lynx, wget, and curl are all disabled.

What finally worked for me was to set up a curl call in a php script as follows:

function process_queue() {
//variables
$domain = "http://www.domain.com/lists/";
$post_data["page"] = "processqueue";
$post_data["login"] = "PHPLIST_LOGIN";
$post_data["password"] = "PHPLIST_PASSWORD";
$url = $domain . "admin/index.php";

//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);

//clean up
curl_close($ch);

return $result;
}
$result = process_queue();


Then I use cron to call this script (saved in a PHP file named "phplist_cron.php" in my home directory) as follows (it runs every 15 minutes this way):

*/15 * * * * php phplist_cron.php


Of course, this solution will require a little adjustment (folder names, etc) to work on other servers but it's the only thing that's worked for me!
Source: forum post by TdonJohnson

Using wget --post-data to pass login data to phplist
I was running into a similar problem to TdonJohnson's - the login information wasn't being passed to the page. The output indicated that the problem was related to trouble with cookies: "In order to login, you need to enable cookies in your browser".
I tried all the recommended options (php, curl, etc), but it was wget that I finally got to work. Turns out that the data got through when I sent it by post instead of get:

wget --post-data "page=processqueue&login=USERNAME&password=PASSWORD" http://your.domain.com/lists/admin/

Source: Forum post by sing1ejack



Useful forum threads




CategoryDocumentation
Page was generated in 0.4154 seconds