Recently, because the project needs to do some processing on the remote database on a regular basis, there is a need to make a plan for what the task looks like.
After the effort, finally using PHP to achieve this scheduled task, the following share the implementation process. The use of the PHP implementation of the planning task is mainly used
Ignore_user_abort () set_time_limit (0) sleep () these three functions.
The specific code is as follows:
Ignore_user_abort ();//The function is that when the user shuts down the browser, the PHP script can continue to execute.
Set_time_limit (3000);//Set_time_limit (0) allows the program to execute indefinitely
$interval =5;//Run every 5s
Method of Death Cycle
do{
echo ' Test '. Time (). '
Sleep ($interval);//Wait 5s
}while (TRUE);
Method 2---Sleep timed execution
Require_once './curlclass.php ';//Introduction file
$curl =new httpcurl (' www.phpernote.com ');//instantiation
$stime = $curl->getmicrotime ();
for ($i =0; $i <=10; $i + +) {
echo ' Test '. Time (). '
Sleep ($interval);//Wait 5s
}
Ob_flush ();
Flush ();
$etime = $curl->getmicrotime ();
Echo ';
Echo Round (($etime-stime), 4);//Program Execution time
In the specific implementation process of the individual feel PHP time to perform tasks is not very efficient, it is recommended that the task of timing tasks or to the shell to do it, relatively speaking, this method is too reluctant to achieve, and the shell is a professional level.