Install Crontab:
Yum Install Crontabs
Basic cron Service Control commands:
Code
- /sbin/service crond Start //Start service
- /sbin/service Crond Stop //Shut down service
- /sbin/service crond Restart //Restart service
- /sbin/service Crond Reload //Reload configuration
View crontab Service Status: Crond status
Manually Start crontab services: Service Crond start
To see if the Crontab service is set to boot, execute command: NTSYSV
Join power on Auto start: Chkconfig--level Crond on
If you want to learn more about the Chkconfig--level command, http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html explain it in more detail.
Crontab Command Introduction
Code
- Feature Description: Set the timer.
- Syntax: crontab [-u <用户名称> ] [configuration file] or crontab [-u <用户名称> ][-ELR]
- Additional note: Cron is a resident service that provides the function of a timer that allows the user to execute a preset instruction or program at a specific time. The function of the timer can be used as long as the user edits the timer's configuration file. Its configuration file format is as follows:
- Minute Hour Day Month DayOFWeek Command
- Parameters
- -e Edit the user's timer settings.
- -l lists the user's timer settings.
- -R removes the user's timer settings.
- <用户名称> -u Specifies the name of the user to set the timer.
crontab format
Code
- Basic format:
- * * * * * command
- Time-sharing Weekly command
- The 1th column represents minutes 1~59 per minute with * or */1
- The 2nd column represents the hour 1~23 (0 means 0 points)
- The 3rd column represents the date 1~31
- The 4th column represents the month 1~12
- 5th Column Identification Number Week 0~6 (0 = Sunday)
- 6th List of commands to run
- # Use the hash sign to prefix a comment
- # + —————-minute (0–59)
- # | + ————-Hour (0–23)
- # | | + ———-Day of month (1–31)
- # | | | + ——-Month (1–12)
- # | | | | +--Day of Week (0–7) (sunday=0 or 7)
- # | | | | |
- # * * * * * command to be executed
Some examples of crontab files:
Code
- - * * * * /etc/init.d/nginx Restart
- Every night : re-start Nginx.
- $ 4 1,ten, * */etc/ Init.d/nginx Restart
- 4 : 45 per month, 1,ten, Day Restart nginx.
- Ten 1 * * 6,0 /etc/init.d/nginx restart
- Every Saturday, Sunday of 1 : restart nginx.
- 0 , - * * * * * /etc/init.d/nginx Restart
- Per Day : from xx to : every Restart nginx in five minutes.
- 0 * * 6 /etc/init.d/nginx Restart
- Every Saturday : pm to restart Nginx.
- * * * *1 * * */etc/init.d/nginx restart
- Restart Nginx every hour
- * 7/1 * * */etc/init.d/nginx restart
- In the evening , between 7 o ' Day, restart Nginx every hour .
- 0 4 * mon-wed/etc/init.d/nginx restart
- 4 monthly and every Monday to Wednesday, restart nginx .
- 0 4 1 Jan */etc/init.d/nginx Restart
- 4- Point Restart of nginx on January 1
- * * * * * * * * /usr/sbin/ntpdate 210.72. 145.20
- Synchronize time every half hour
Apply to Thinkphp
First you have to write the function code that you want to execute on a regular basis into the action. Or you can do it after you access it with a URL.
For example, I put the update code for the regular daily traversal of the order to see if the turnover is order/update_status.
My Project Access address is www.jieqinwang.com that is: The code execution path for this feature is: Http://www.jieqinwang.com/Order/update_status
After you get this path, you can go to Liunx to configure Cron.
Crontab-e into the task list.
Press the I key to enter edit mode, and then add a task.
For example, I want to execute the code I just wrote every day 12 o'clock noon.
Just add a new line 0 * * * * Curl Http://www.jieqinwang.com/Order/update_status
Then press the ESC key to exit edit mode and enter: Wq enter. Save exit.
This allows us to add a timed task. You can use Crontab-l to see if the task list is already contained.
The last step, as such additions may not take effect immediately. We can restart the cron service.
Restart Service command: / sbin / service crond restart
Original link: http://164418960.iteye.com/blog/2170536
The above describes the Linux crontab command, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.