Click to See Complete Forum and Search --> : [Resolved] Passing Parameters with a Cron Job


David Wood
04-28-2005, 01:29 PM
Is there a way to pass a parameter with a Cron job?

I have a Cron job set up to run a php script and I would like to be able to pass a parameter with it ie. my_job.php?mode=run just as I would within a page.

If I try to do this I get an error back saying that it "Could not open input file: my_job.php?mode=run".

The Cron job runs fine without the parameter so it is the parameter that is causing the problem.

Any ideas?

mtmosier
04-28-2005, 01:52 PM
If you're using php compiled as a cgi binary then you can run
php my_job.php "mode=run"
If it's not compiled as a cgi binary you can still use the above and put this at the top of your file.

if (empty($_GET) && !empty($_SERVER['argv'][1])) {
parse_str($_SERVER['argv'][1], $_GET);
}

Or, for that matter, you could just use
php my_job.php run
and in your script do
$mode = $_SERVER['argv'][1];

David Wood
04-29-2005, 04:45 AM
Thanks for that mtmosier - it works great:)