Knowledgebase

Can I use command line arguments with a PHP scheduled task?

Using command line arguments with PHP requires the use of the $argv array. This is only avaialble if the register_argc_argv setting is enabled, but this is disabled by default.

To enable register_argc_argv you would need to create a php.ini file in your web space (or edit the existing one) and include this line:

register_argc_argv = On

You can then specify this php.ini file in the command for the scheduled task, for example:

 /usr/bin/php5 -c /home/sites/domain.com/php.ini /home/sites/domain.com/cron.php argument1 argument2

The PHP script will then be able to use the specified arguments.