Introduction: How to simulate those automatic round-robin services, like the daemon (Daemon) , can be executed, never stop!
Come on! Do it! Do! Do! Do!....
Using interfaces:
int ignore_user_abort ([bool setting])
Method declaration:
The purpose of this function is to indicate whether the server side continues to execute the following script after the remote client closes the connection.
Parameter description:
Setting: parameter is an optional parameter. If set to True, this means that if the user stops the script, it still does not affect the script's run (that is, the script will continue to execute), and if set to False, indicates that when the user stops running the script, The scripting program will stop running .
Speaking so much, is not as direct as a line of code to effectively, directly engaged.
Basic example
In the following example, after the user closes the browser , the script continues to execute on the server:
<?PHP//running in the backgroundIgnore_user_abort();//maximum timeout for canceling script run timeSet_time_limit(0);//perform round robin Do { //sleep for 1 minutes Sleep(60); //dealing with specific things Echo' Do! ';} while(true);?>
Description: This code will be executed forever unless the program is closed on the server.
Example 1 for extended display
Mark, we are interested to have a look.
Implementation features: record time every 10 seconds to file, never stop.
<?PHP//running in the backgroundIgnore_user_abort();//maximum timeout for canceling script run timeSet_time_limit(0);//debug Log [start]Echo' Start. ';//perform round robin while(!file_exists(' Close.txt ')) { //Open File $handle=fopen(' Test.txt ', ' A + '); //Write Date fwrite($handle,Date("Y-m-d h:i:s"). "It worked!" \ n "); //Close File fclose($handle); //sleep for 10 seconds Sleep(60);}//debug Log [end]Echo' End. ';?>
This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4793943.html
[PHP Learning Tutorial]002. Simulation Daemon (Daemon)-The program is always running in the background