First of all, Cron, it's a timed execution tool under Linux. Users other than the root user can use the Crontab tool to configure cron tasks. All user-defined crontab are saved in the/var/spool/cron directory and executed using the user who created them. To create a crontab project as a user, log on as the user, and then type the CRONTAB-E command to edit the user's crontab. The file uses the same format as the/etc/crontab. When a change to crontab is saved, the crontab file is saved according to the user name and written to the file/var/spool/cron/username. The cron daemon examines changes in/etc/crontab files, etc/cron.d/directories, and/var/spool/cron directories every minute. If a change is found, they will be loaded into memory. This way, you do not have to restart the daemon when a crontab file changes.
Install Crontab:
Yum Install Crontabs
Description
/sbin/service Crond Start//Startup 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
Add to boot auto start:
Chkconfig–level Crond on
Each hour executes myscript.php as follows:
12 |
# crontab -e 00 * * * * /usr/local/bin/php /home/john/myscript.php |
If your PHP script can be triggered by a URL, you can use Lynx or curl or wget to configure your crontab.
The following example uses the Lynx text browser to access the URL to execute PHP scripts every hour. The Lynx text browser opens the URL by default using dialog. However, like the following, we use the-dump option in the Lynx command line to convert the output of the URL to standard output.
1 |
00 * * * * lynx -dump http: //www.jb51.net/myscript.php |
The following example uses Curl to access the URL to execute PHP scripts every 5 minutes. Curl defaults to show output in standard output. With the "curl-o" option, you can also dump the output of the script to a temporary file.
1 |
*/5 * * * * /usr/bin/curl -o temp.txt http: //www.jb51.net/myscript.php |
The following example uses the wget access URL to execute PHP scripts every 10 minutes. The-q option indicates quiet mode. "-O Temp.txt" indicates that the output is sent to a temporary file.
1 |
*/10 * * * * /usr/bin/wget -q -O temp.txt http: //www.jb51.net/myscript.php |
Parameters
-e Edit the user's timer settings.
-l lists the user's timer settings.
-R removes the user's timer settings.
-u< User name > Specifies the user name to set the timer.
Crontab format:
Basic format:
Minute hour Sun Moon Week 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
Remember the meanings of several special symbols:
"*" represents a number in the range of values,
"/" stands for "every",
"-" represents a number to a number,
"," separate a few discrete numbers
Some examples of crontab files:
* * * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that 21:30 restarts Apache per night.
4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.
1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.
0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows the restart of Apache every Saturday at 11:00am.
0 */1 * * */usr/local/etc/rc.d/lighttpd restart
Restart Apache every hour
0 23-7/1 * * */usr/local/etc/rc.d/lighttpd restart
From 11 o'clock to 7 in the morning, restart Apache every hour.
0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart
4th per month with 11-point restart from Monday to Wednesday Apache
0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart
Reprinted from Https://www.cnblogs.com/vania/p/6480312.html
How to use Linux crontab timed php script execution method [reprint]