Passing variables to php via cron

I’ve recently moved server and updated versions of php/apache and now I’m having trouble passing varables to scripts run under crontab.

I was running the cron like:
php /path_to_script/script.php “foo=bar”

and the foo would be available to the script under the $_GET array.

But now the $_GET array is empty. Is there a something in the php/apache config which enables/disables this behaviour?

When you run php via the command line, there isn’t a web server. $_GET and $_POST etc… don’t make sense in a non webserver environment. I’m not sure what was going on in your last server. Maybe the server admin had the php command aliased to something else, or an auto_prepend_file was set in php.ini

You could probably use something like this at the top of the script


parse_str($_SERVER['argv'][1], $_GET);


php /path_to_script/script.php "foo=bar&blah=5"

Cheers. I had assumed that the behaviour on my previous server was the ‘proper’ one. But I’ll use parse_str on the argv. Cheers.