Ext.: https://www.centos.bz/2011/03/auto-run-task-crontab/
Our PHP program sometimes needs to be executed periodically, we can use the Ignore_user_abort function or put JS on the page to let the user help us to achieve. But neither of these methods is reliable and unstable. We can use the Linux crontab tool to reliably trigger PHP to perform tasks.
Here are two ways to crontab.
First, use PHP to execute script in crontab
Just like calling a normal shell script in crontab, use a PHP program to invoke the PHP script.
Each hour executes myscript.php as follows:
- # CRONTAB-E
- XX * * * */usr/local/bin/php/home/john/myscript.php
/usr/local/bin/php is the path to the PHP program.
Second, use URL to execute script in crontab
If your PHP script can be triggered by a URL, you can use Lynx or curl or wget to configure your crontab.
The following example uses the Lynx text browser to access the URL to execute PHP scripts every hour. The Lynx text browser opens the URL by default using dialog. However, like the following, we use the-dump option in the Lynx command line to convert the output of the URL to standard output.
- XX * * * * lynx-dump http://www.centos.bz/myscript.php
The following example uses Curl to access the URL to execute PHP scripts every 5 minutes. Curl defaults to show output in standard output. With the "curl-o" option, you can also dump the output of the script to a temporary file.
- */5 * * * */usr/bin/curl-o temp.txt http://www.centos.bz/myscript.php
The following example uses the wget access URL to execute PHP scripts every 10 minutes. The-q option indicates quiet mode. "-O Temp.txt" indicates that the output is sent to a temporary file.
- */10 * * * */usr/bin/wget-q-o temp.txt http://www.centos.bz/myscript.php
http://www.bkjia.com/PHPjc/815206.html www.bkjia.com true http://www.bkjia.com/PHPjc/815206.html techarticle turn: https://www.centos.bz/2011/03/auto-run-task-crontab/Our PHP program sometimes needs to be executed at timed intervals, we can use Ignore_user_ Abort function or in the page to place JS let the user help ...