Recently, because the project needs to do some processing on the remote database regularly, there is a need to do a planning task. After efforts to finally use PHP to achieve this planning task, the following share the implementation process.
This time using the PHP implementation planning task mainly uses the Ignore_user_abort () set_time_limit (0) sleep () these three functions.
The specific code is as follows:
<?php
Ignore_user_abort ()//The function is that the PHP script can continue to execute after the user has turned off the browser.
Set_time_limit (3000);//Through Set_time_limit (0) allows the program to execute indefinitely
$interval =5;//every 5s run
//Method 1--dead loop
do{
echo ' Test '. Time (). ' <br/> ';
Sleep ($interval);//wait 5s
}while (true)
; Method 2---Sleep timed execution
require_once './curlclass.php '//File
$curl =new httpcurl (' www. Alixixi.com ')//instantiate
$stime = $curl->getmicrotime ();
For ($i =0 $i <=10; $i + +) {
echo ' Test '. Time (). ' <br/> ';
Sleep ($interval);//wait for 5s
}
Ob_flush ();
Flush ();
$etime = $curl->getmicrotime ();
Echo '
In the specific implementation of the process of personal feeling PHP time to perform the task of the efficiency is not high, suggest that the task of scheduled tasks or to the shell to do it, relatively speaking, this approach to achieve too reluctantly, and the shell is professional level.
Articles that you may be interested in
- Win7 set up for scheduled tasks
- PHP statistics online numbers, accurate statistics online number of ways
- PHP Records search engine antecedents and search input keywords
- PHP to determine the most secure upload file type, the most realistic solution
- What is the PHP design pattern and how do you understand
- Use PHP functions in Smarty Templates and how to use multiple functions for a variable in smarty templates
- The operating mechanism and principle of PHP bottom
- PHP gets the last day of any month