PHP will not detect if the user has disconnected until it attempts to send information to the client. Simply using the echo statement does not ensure that the message is sent, see the flush() function.
The code is as follows 代码如下 | 复制代码 | ignore_user_abort(true); set_time_limit(0); while(1) { $fp = fopen('time_task.txt',"a+"); $str = date("Y-m-d h:i:s")."nr"; fwrite($fp,$str); fclose($fp); sleep(5); //半小时执行一次 } ?> | |
Copy code
|
ignore_user_abort(true); set_time_limit(0); while(1) { $fp = fopen('time_task.txt'," a+"); $str = date("Y-m-d h:i:s")."nr"; fwrite($fp,$str); fclose($fp); sleep(5); //Execute once every half hour } ?>
Definition and usage ignore_user_abort() function settings Whether disconnecting from the client terminates script execution. |
This function returns the previous value (a Boolean value) set by user-abort.
Syntaxignore_user_abort(setting) Parameter Description
setting Optional. If set to true, disconnects from the user are ignored, if set to false, causes the script to stop running.
If this parameter is not set, the current setting will be returned. Tips and NotesNote: PHP will not detect if the user has disconnected until trying to send information to the client. Simply using the echo statement does not ensure that the message is sent, see the flush() function. Here is an article you can refer to http://www.bkjia.com/phper/php/php-ignore_user_abort.htm
http://www.bkjia.com/PHPjc/444703.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444703.htmlTechArticlePHP does not detect if the user has disconnected until an attempt is made to send information to the client. Simply using the echo statement does not ensure that the message is sent, see the flush() function. The code is as follows...