Home  >  Article  >  Backend Development  >  PHP scheduled task ignore_user_abort function implementation_PHP tutorial

PHP scheduled task ignore_user_abort function implementation_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:10:41908browse

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.

This function returns the previous value (a Boolean value) set by user-abort.
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.

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.

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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn