Home >Backend Development >PHP Tutorial >How to Schedule a PHP Script with Cron Jobs in cPanel?
How to Run a PHP Script as a Cron Job in CPanel
Running PHP scripts on a scheduled basis using cron jobs is a common task for website maintenance. The provided syntax is not the most appropriate for this purpose.
Corrected Syntax:
To schedule a PHP script to run at a specific time, use the following syntax:
/usr/bin/php -q /home/username/public_html/yourfilename.php
Fixing Email Notifications:
Email notifications are sent when a cron job completes successfully or fails. To ensure that you receive these notifications, your PHP file should have the following properties:
Revised Syntax for Cron Job:
With these corrections, the revised syntax for running a PHP script using a cron job in CPanel is:
/usr/bin/php -q /home/username/public_html/yourfilename.php >& /dev/null
The above is the detailed content of How to Schedule a PHP Script with Cron Jobs in cPanel?. For more information, please follow other related articles on the PHP Chinese website!