Author: Zhu Maohai Category: FAQ release time: 2011-07-23 12:00ė778 views 611 article Catalog [hide] First, use PHP to execute script in crontab Two, use URL to execute script in crontab
Our PHP program sometimes needs to be executed periodically, we can use the Ignore_user_abort function or place JS on the page to let the user help us achieve. Neither of these methods is reliable or stable. We can use Linux's crontab tools to reliably trigger PHP to perform tasks.
Here are two ways to crontab.
first, use PHP to execute scripts in crontab
Just like calling a normal shell script in crontab (specifically crontab usage), use a PHP program to invoke the PHP script.
Every hour the execution myscript.php is as follows: # CRONTAB-E * * * * * * */usr/local/bin/php/home/john/myscript.php
/usr/local/bin/php is the path to the PHP program. ii. using URLs to execute scripts 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 a Lynx text browser to access URLs to execute PHP scripts every hour. The Lynx text browser opens the URL by default using the dialog method. However, like the following, we use the-dump option in the Lynx command line to convert the URL output to standard output. * * * * * * lynx-dump https://www.centos.bz/myscript.php
The following example uses the Curl access URL to execute a PHP script every 5 minutes. Curl defaults to display 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 https://www.centos.bz/myscript.php
The following example uses the wget access URL to execute a PHP script 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 https://www.centos.bz/myscript.php
This article comes from the Linux server operation log, please indicate the source and the corresponding link.
This article permanent link: https://www.centos.bz/2011/07/php-cron-job-linux-crontab/0 crontab, PHP