Use cronjob in linux to regularly execute php scripts.

Source: Internet
Author: User

Use cronjob in linux to regularly execute php scripts.

Enter commands in linux

crontab -e

Then, use the vim command to edit the opened file and enter

0 * * * * /usr/bin/php -f /home/userxxx/update.php

Save and exit. Now, the system will automatically execute the update. php script at each time. The script can be used to write database execution, automatic mail, and other functions.

Note: Writing 0 *** php-f/home/userxxx/update. php does not work.

In addition, the cronjob format is:

MIN HOUR DOM MON DOW CMD

Field Description Allowed Value
MIN Minute field 0 to 59
HOUR Hour field 0 to 23
DOM Day of Month 1-31
MON Month field 1-12
DOW Day Of Week 0-6 (0 indicates Sunday)
CMD Command Any command to be executed.


Use (-) to define the scope

For example, 0 0-6 *** command indicates that the command is executed at every day.

Use (,) to enumerate the time

For example, "0, 15, 30, 45 *** command" indicates that the command is executed at, and each hour.

Use (/) to specify the interval

For example, **/4 ** command indicates that the command is executed every four hours.

Combination

0-10/2 *** command indicates that the command is executed every two minutes in the first 10 minutes.

Related Article

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.