This article introduces how to use crontab to execute PHP programs regularly in Linux systems. Friends in need can refer to it.
How to use Crontab to execute PHP regularly in Linux. The implementation steps are as follows: 1. Use crontab -e to edit scheduled tasks The content is: xx:xx:xx executes a hello.php file2. The php file must be in the first line of the file, plus the interpreter path (similar to bash or perl) #!/usr/local/bin/phpNote: The execution of PHP requires the support of Apache, the execution of shell script requires the support of Linux, and Linux supports the function of running a certain program regularly. Then, execute it directly in /etc/crontab, as follows: */5 * * * * root /root/hello.phpThe previous method was to first execute a shell program in crontab, and then let the shell program run the PHP program. This is actually quite inefficient; Instead, add the php path directly to /etc/crontab, such as */5 * * * * root php hello.php, can also be executed correctly; |