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
Related Articles
Why is my custom php.ini file not working?
Added on Thu, Apr 9, 2015
How do I connect to MySQL with ASP?
Added on Thu, Feb 26, 2015
How do I connect to my MySQL database from my Perl script?
Added on Thu, Feb 26, 2015
What is Python?
Added on Fri, Mar 13, 2015
What is Perl and what can it do?
Added on Fri, Mar 13, 2015