How to pass parameters to a PHP file in a cron job

This is just a quick tip but it annoyed the bejaysus out of me for about an hour. I was running the job in the following format:

00*** test_file.php?a=1&b=2&c=3

But an error was getting thrown saying that the input file, test_file.php?a=1&b=2&c=3, could not be found. With some help from the Google machine, I found that the correct format should be:

00*** test_file.php 1 2 3

And in your PHP file you can use the $argv variable to get at the paramter values

$a = argv[1];
$b = argv[2];
$c = argv[3];

And that should do the trick.

This entry was posted in Web Development and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>