Home » Categories » Multiple Categories

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

You can use command line arguments, but you need to use the $argv array.  And the $argv array is only available if the register_argc_argv setting is enabled in PHP.

This is disabled by default, but you can create a php.ini file to enable register_argc_argv.

To enable this setting:

  1. Download your existing php.ini or create a new one in your text file
  2. Add the following line:

register_argc_argv = On

  1. Upload the file

You can then specify this particular php.ini file in the command for the scheduled task.  For example, if you use:

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

The cron.php file will be able to use argument1 and argument2 when running.

2 (4)
Article Rating (4 Votes)
Rate this article
  • Icon PDFExport to PDF