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

The three interfaces of PHP

This page briefly describes the different interface versions of PHP. This may be important when setting up a cron job or commandline script. Both the title and the basic content of this article are based on a forum post from jotazzu, with some additions and edits from my part

Each version of PHP (since 4.3.0) exists in 3 different interface versions: the HTTP interface, and the CLI and CGI interface. All have the same version number but the methods of calling a PHP script are different.

The HTTP interface
The best known interface of PHP is the HTTP interface implemented in the PHP-Apache-Module, which is not standalone and which is used for the classical HTTP request (like This interface is used when making calls to PHPlist with a standard browser. A typical example of calling a script with the HTTP interface is:

Both the CGI (Common Gateway Interface) version and the CLI (Command Line Interface) version of PHP are standalone programs. You do not need another program, like the Apache web server, to execute PHP pages. However, both interfaces have marked differences in the way they should be treated.

The PHP-cgi interface
The CGI interface behaves much in the same way as when calling PHPlist with a browser, even though it's not using the HTTPD protocol:
The config.php file cannot be loaded into environment, which is similar to the the HTTP interface. This means you need to specify the login name and password for access to the PHPlist admin module as you would with a browser.
Also, the parameters are identical to the call with a browser, despite the fact that the PHP script is called as a local file and not as a web address, and even though the '?' and '&' are removed.
Most -if not all- timeouts are active in the CGI version. For queue processing this is 600 seconds, though in reality this may reach up to 1200 seconds (20 minutes). This implies you may have to reload the command in order to process all messages (see also cron job examples).

Note the similarities with the HTTP calling method in this typical example of calling a script with the PHP-cgi interface from the command line:

/bin/usr/php /home/ page=processqueue login=myusername password=mypassword >/dev/null

You can also use the Lynx text browser, Wget, Get or cURL, if available on your server. Here are some examples how you could use these from the commandline:

lynx -dump '' >/dev/null

wget -q -O - '' >/dev/null

GET '' >/dev/null

curl -s '' >/dev/null

the PHP-cli interface
Things are quite different when using the CLI version of PHP: You do not need to specify login information. Instead the value of the environment variable USER is compared against the entries in the array $commandline_users in config.php. Only if a match is found, will the script be executed.
The parameters used with PHP-cli differ from the CGI version. The page to execute is set with the parameter -p and to load the relevant values contained in the config.php file you use the -c parameter. Incidentally, the allowed parameters do not depend on PHP-cli, but on what is programmed in PHPlist.

A typical example of calling a script with the PHP-cli interface is:

USER=listprocessor; export USER; /usr/bin/php /home/mydomain/lists/admin/index.php -pprocessqueue -c/home/mydomain/lists/config/config.php

or, when using a commandline script:

/sbin/phplist -pprocessqueue

Of course, these commands can easily be placed in a crontab file and scheduled to be executed on a predefined time. For more information, please read setting up cron jobs and using a command line script. You may find it useful to look at some of the working examples forum users have provided: cron job examples.

For more information on PHP-cli and PHP-cgi, please read Using PHP from the command line, and CGI and commandline setups.

How to determine the PHP interface version of your server

If you have commandline access you can use the following method to determine which PHP interface version your server is running. From the command line prompt type the following command: php -v

If your server is running PHP-cli, you should see something similar to this:

PHP 4.3.3 (cli) (built: Jun 8 2004 19:27:04)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

If your server is running PHP-cgi, something like this would be displayed:

PHP 4.3.3 (cgi) (built: Nov 10 2003 13:05:54)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

Page was generated in 0.0867 seconds