Sometimes it takes a timed task to monitor a program. Requires the program to run automatically.
1, Ignore_user_abort ()
The Ignore_user_abort () function is paired with Set_time_limit (0) and sleep ($interval) to enable the program to run updates automatically.
Example:
PHP scripts can continue to execute even if the client disconnects (such as turning off the browser).
Ignore_user_abort ();
Execution time is unlimited, php default execution time is 30 seconds, through Set_time_limit (0) can allow the program to execute indefinitely
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 5 minutes
Sleep ($interval);
}while (TRUE);
Just run the page above and then turn it off, and the program will run all the way down.
2, Crontab
There's an easier way to do Linux under the crontab command.
The function of the crontab command is to schedule execution of some commands at certain intervals.
Crontab How to use: crontab [-e |-l |-r] FileName-E: Edit Task-L: Show task Information-r: Delete scheduled execution task information
Format of crontab:
* * * * * Command
Time-sharing day and month command to run
Examples of crontab: