Sometimes, we want to create cron job using PHP.
In this article, we’ll look at how to create cron job using PHP.
How to create cron job using PHP?
To create cron job using PHP, we can create a PHP script and add it to the crontab file.
For insrtance, we write
<?php
echo "hello";
and save the file to /usr/local/bin/run.php
Then in crontab, we add
* * * * * /usr/bin/php -f /usr/local/bin/run.php &> /dev/null
to add the /usr/local/bin/run.php script to run run.php as a scheduled job.
We may give the script execute permission with
chmod +x /usr/local/bin/run.php
Once it has execute permission, we can omit /usr/bin/php -f
from crontab.
Conclusion
To create cron job using PHP, we can create a PHP script and add it to the crontab file.