Home  >  Article  >  Backend Development  >  Implementing scheduled execution of php scripts under linux_PHP tutorial

Implementing scheduled execution of php scripts under linux_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:06:37802browse

Realizing scheduled execution of php scripts under Linux

This article mainly introduces the method and specific usage examples of implementing scheduled execution of php scripts under Linux. It is a very good article and is recommended here. Everyone.

Enter commands in linux

The code is as follows:


crontab -e

Then use the vim command to edit the open file and enter

The code is as follows:


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

Save, exit, okay, now the system will automatically execute the update.php script at every 0 o'clock. In the script, you can write functions such as database execution and automatic email sending.

Note: Directly writing 0 * * * * php -f /home/userxxx/update.php will not work.

In addition, the format of cronjob 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表示星期天)
CMD Command Any command to be executed.

Use (-) to delimit the range

For example: 0 0-6 * * * command means executing command

from 0-6 o'clock every day

Use (,) to enumerate time

For example: 0,15,30,45 * * * * command means that command will be executed at 0 minutes, 15 minutes, 45 minutes and 30 minutes of each hour

Use (/) to specify the interval

For example: * */4 * * * command means executing command every four hours

Combined usage

0-10/2 * * * * command means executing command

every 2 minutes in the first 10 minutes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/958127.htmlTechArticleRealizing scheduled execution of php scripts under Linux This article mainly introduces the methods and details of implementing scheduled execution of php scripts under Linux Usage examples, very good article, recommended to everyone here. In...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn