The two methods of Crontab are introduced below.
1. Use PHP to execute scripts in Crontab
Just like calling an ordinary shell script in Crontab (specific Crontab usage), use the PHP program to call PHP script.
Execute myscript.php every hour as follows:
Copy the code The code is as follows:
# crontab -e
00 * * * * /usr/local/bin/php /home/john/myscript.php
/usr/local/bin/php is the path of the PHP program.
2. Use URL to execute scripts in Crontab If your PHP script can be triggered by URL, you can use lynx or curl or wget to configure your Crontab .
The following example uses Lynx text browser to access a URL to execute a PHP script every hour. Lynx text browser uses conversational mode to open URLs by default. However, as shown below, we use the -dump option on the lynx command line to convert the URL output to standard output.
Copy code The code is as follows:
00 * * * * lynx -dump http://www.jb51.net/ myscript.php
The following example uses CURL to access the URL to execute a PHP script every 5 minutes. Curl displays output on standard output by default. You can also dump the script's output to a temporary file using the "curl -o" option.
Copy code The code is as follows:
*/5 * * * * /usr/bin/curl -o temp.txt http://www.jb51.net/myscript.php
The following example uses WGET to access the URL to execute a PHP script every 10 minutes. The -q option indicates quiet mode. "-O temp.txt" means the output will be sent to a temporary file.
Copy code The code is as follows:
*/10 * * * * /usr/bin/wget -q -O temp .txt http://www.jb51.net/myscript.php
http://www.bkjia.com/PHPjc/324643.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324643.htmlTechArticleThe two methods of Crontab are introduced below. 1. Use PHP to execute scripts in Crontab. Just like calling a normal shell script in Crontab (specific Crontab usage), use a PHP program to call...