Sometimes scheduled tasks are required to monitor a program. The program must run automatically. 1. the ignore_user_abort () function can be used with set_time_limit (0) and sleep ($ interval) to automatically update programs. Example: 1234567891011121314151617 even if Cl... sometimes requires scheduled tasks to monitor a program. The program must run automatically.
1. ignore_user_abort ()
The ignore_user_abort () function works with set_time_limit (0) and sleep ($ interval) to automatically update programs.
Example:
// Even if the Client is disconnected (such as closing the browser), the PHP script can continue to be executed.
Ignore_user_abort ();
// The execution time is unlimited. the default php execution time is 30 seconds. you can use set_time_limit (0) to allow unlimited execution of the program.
Set_time_limit (0 );
// Run every 5 minutes
$ Interval = 60*5;
Do {
$ Url = "http://yaolei.info ";
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 2 );
$ Result = curl_exec ($ ch );
Curl_close ($ ch );
// Wait for 5 minutes
Sleep ($ interval );
} While (true );
As long as you run the above page, and then turn it off, the program will continue to run.
2. crontab
In Linux, there is a simpler method, that is, the crontab command.
The crontab command schedules the execution of some commands at certain intervals.
Crontab usage: crontab [-e |-l |-r] file name-e: edit task-l: Display task information-r: delete scheduled execution task information
Crontab format:
* *** Command
Command to be run by hour, day, month, and week
Crontab example: