larger smaller normal text version of this page

Formatting code for CommandLineScriptExamples


show source only

==[[PhplistDocumentation Phplist Documentation]] » [[MessageFunctionsInfo Message functions]] » [[ProcessQueueInfo Process the message queue]] » ==
----
=====Commandline Script Examples =====

//This page provides some examples of commandline scripts applied by Phplist users. You are welcome to add your commandline script. Please include a brief description of what it does.//


===Commandline script that checks for running processes===

%%(php)#!/bin/bash

#Just check if the script is running if it is about otherwise run the script
if [ `ps aux |grep phplist | grep -c -v 'grep'` -eq 0 ]
then
echo "" >> /var/log/list.log
echo "`date`" >> /var/log/list.log
/usr/local/bin/phplist -pprocessqueue >> /var/log/list.log
else
exit 0
fi
%%
This is a little bash script that I use to get around the problem of having the process queue already running when the cronjob calls it. I don't actually call the phplist command from the cronjob but rather call this shell script which just checks to see if phplist is running and if it is exits otherwise if it isn't it will call the phplist -processqueue command. I have noticed that phplist takes a lot out of mysql so you definitely wouldn't want to have 2 process queues running at once. I imagine you could write a batch file that does the same thing pretty easily. Source: [[http://forums.phplist.com/viewtopic.php?p=8877#8877 Forum post by habbers]]


===Commandline script that checks for user variable===

%%(php)#!/bin/bash

# Place config data in environment
export CONFIG

# Check the USER environment variable is set
if [$USER]; then
echo found USER variable
else
USER=listprocessor
export USER
fi

# run the PHPlist index file with all parameters passed to this script
/usr/bin/php /home/website/public_html/lists/admin/index.php $*

%%
After edited the phplist file to reflect the locations of my config.php and admin/index.php file, I inserted a check in my "phplist" commandline file which would set the USER environment variable (if it wasn't already set).
I relocated this to a location away from my public html files ( say /usr/local/cron_scripts ) and point to this in my cronjob line:

%%(php)# every hour at 15 minutes past we process the queued messages
15 * * * * /usr/local/scripts/phplist -pprocessqueue

%%

I found no need to include any login or password variables in the call to the admin/index.php file. The problem for me was that a cronjob does not have a USER environment variable set and it is from this that the admin/index.php file checks against commandline_users.
The solution was to create a pseudo (non existent) user in the commandline_users variable in the config.php file. so ...

%%(php)$commandline_users = array("listprocessor","any other","users","you want","to set");%%
Finally I made sure the phplist file is executable (chmod 755). Source: [[http://forums.phplist.com/viewtopic.php?p=8040#8040 Forum post by cafamily]]


===Commandline script that logs the start and end of processing===

**Settings in config.php**

%%(php)
define("MAILQUEUE_BATCH_SIZE",50);
define("MAILQUEUE_BATCH_PERIOD",500); // irrelevant with CLI and cron
define('MAILQUEUE_THROTTLE',2);
$commandline_users = array("admin","listprocessor");%%

**Commandline script**

%%(php)
#!/bin/bash
# identify the config file for your installation
CONFIG=/var/www/lists/config/config.php

ISCLI=TRUE
[ -z $USER ] && USER=admin
PROCESS=$$
export CONFIG ISCLI USER
LOGFILE=/var/www/lists/log/phplist.log
echo "Process $PROCESS started on 'date'">>$LOGFILE

# run the PHPlist index file with all parameters passed to this script
/usr/bin/php /var/www/lists/admin/index.php $*>> $LOGFILE 2>&1
echo "Process $PROCESS ended on 'date'">>$LOGFILE
%%
The definition of the users is important, otherwise phplist will not allow processing.

**Cron job**
The next step is to set up the cron job and execute the script every 10 minutes (remember to change the paths):

%%10 * * * * /var/www/phplist/lists/phplist -pprocessqueue -c/var/www/lists/config/config.php%%
Source: [[http://www.contentschmiede.de/archiv/2006/08/07/das_newsletter-tool_phplist/#cron Die ContentSchmiede]]



===Other Tips & Tricks from the forum===

- [[http://forums.phplist.com/viewtopic.php?t=9856 Solution for the user environment variable issue]]


==Related pages==
- [[MessageFunctionsInfo Message functions]]
- [[CronJobExamples Cron job examples]]
- [[ProcessQueueInfo Process the message queue]]
- [[PhpListConfigSendRate Setting the send speed]]
----
CategoryDocumentation
Page was generated in 0.0334 seconds