How to use Linux Crontab to regularly execute PHP scripts _ PHP Tutorial

Source: Internet
Author: User
How to use Linux Crontab to regularly execute PHP scripts. The following describes two methods of Crontab. 1. using PHP in Crontab to execute the script is like calling a common shell script in Crontab (specific Crontab usage). using the PHP program to call the following two methods of Crontab are described below.

1. use PHP to execute scripts in Crontab

Just like calling a common shell script in Crontab (specific Crontab usage), you can use a PHP program to call the PHP script.
Execute myscript. php every hour as follows:

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 the URL in Crontab to execute the script

If your PHP script can be triggered through a URL, you can use lynx, curl, or wget to configure your Crontab.
The following example uses the Lynx text browser to access the URL and execute the PHP script hourly. By default, the Lynx text browser opens a URL in dialog mode. However, as shown below, we use the-dump option in the lynx command line to convert URL output to standard output.

The code is as follows:


00 *** lynx-dump http://www.jb51.net/myscript.php


The following example uses CURL to access the URL and execute the PHP script every 5 minutes. Curl displays the output in standard output by default. With the "curl-o" option, you can also dump the script output to a temporary file.

The code is as follows:


*/5 */usr/bin/curl-o temp.txt http://www.jb51.net/myscript.php


The following example uses the wget url to execute the PHP script every 10 minutes. -The q option indicates quiet mode ." -O temp.txt "indicates that the output will be sent to a temporary file.

The code is as follows:


*/10 ***/usr/bin/wget-q-O temp.txt http://www.jb51.net/myscript.php

Bytes. 1. use PHP to execute the script in Crontab, just like calling a common shell script in Crontab (specific Crontab usage). Use a PHP program to call the script...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.