I have a cron job set like
php /home/novinarb/public_html/index.php --uri=\"cron/24satahr\"
but the \'uri\' param doesn\'t get to the php
Is the php script running at all?
I suspect you need to provide the full path to php in your crontab line. Even though cron jobs run as you, they don't have any of your login environment set up; this means they don't have your $PATH.
I was facing the same problem but was able to fix it after reading the manual entry for php.
Initially I had something set like:
/usr/bin/php -f /path/to/php/script.php -c 1426 >> /tmp/script.php.log 2>&1
I was able to fix it by changing the line to:
/usr/bin/php -f /path/to/php/script.php -- -c 1426 >> /tmp/script.php.log 2>&1
As per the manual entry the syntax is:
php [options] [ -f ] file [[--] args...]
Also,
args... Arguments passed to script. Use '--' args when first argument starts with '-' or script is read from stdin
Going by that, my cron command becomes:
/usr/bin/php -f /path/to/php/script.php -- -c 1426 >> /tmp/script.php.log 2>&1
and it works!
A more robust method would be to accept command-line arguments in your PHP script with getopt() or $argv and making it executable. An example with $argv
called script.php
:
#!/usr/bin/php
<?php
if (isset($argv[1])):
echo $argv[1];
endif;
?>
Make it executable:
chmod +x script.php
And execute:
./script.php "cron/24satahr"
Will output:
cron/24satahr