Execute a PHP script using CRON
In response to this post, I’ve received the following email:
“How can I execute a PHP page using CRON? I’m trying ‘php -q /path/script.php’ but it does nothing..“
Note: It’s very likely that your PHP binary is outside of the default PATH cron uses.
We have 2 options, add the PHP binary path to cron, or use the full path in the cron job.
Option 1:
Path of PHP binary:/shared/php5/bin/php
Path of PHP script: /home/foo/bar/script.php
0 */2 * * *: at 0 minutes, every 2 hours, every day, every month, every day of week
0 */2 * * * /shared/php5/bin/php -q /home/foo/bar/script.php
Option 2:
Path of PHP script: /home/foo/bar/script.php
0 */2 * * *: at 0 minutes, every 2 hours, every day, every month, every day of week
Open up the cron table (crontab -e) and add your PHP binary path to the PATH variable.
0 */2 * * * php -q /home/foo/bar/script.php
Leave a Reply
You must be logged in to post a comment.