Home > Backend Development > PHP Tutorial > PHP scheduled task ignore_user_abort function implementation method, ignoreuserabort_PHP tutorial

PHP scheduled task ignore_user_abort function implementation method, ignoreuserabort_PHP tutorial

WBOY
Release: 2016-07-13 10:10:03
Original
938 people have browsed it

Implementation method of ignore_user_abort function of PHP scheduled task, ignoreuserabort

The example in this article describes how to implement the ignore_user_abort function of PHP scheduled tasks. Share it with everyone for your reference. The specific analysis is as follows:

PHP will not detect whether the user has disconnected until trying to send information to the client. Simply using the echo statement cannot ensure that the information is sent. See the flush() function, the code is as follows:

Copy code 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); //Execute once every half hour
}
?>

Definition and usage

ignore_user_abort() function sets whether disconnecting from the client will terminate the execution of the script. This function returns the previous value (a Boolean value) set by user-abort.

Syntax:ignore_user_abort(setting)

参数 描述
setting 可选,如果设置为 true,则忽略与用户的断开,如果设置为 false,会导致脚本停止运行,如果未设置该参数,会返回当前的设置.

Tips and Notes

Note:PHP will not detect whether the user has disconnected until trying to send information to the client. Simply using the echo statement cannot ensure that the information is sent, see the flush() function.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/939400.htmlTechArticleImplementation method of ignore_user_abort function of PHP scheduled task, ignoreuserabort This article describes the implementation method of ignore_user_abort function of PHP scheduled task. Share it with everyone for your reference. ...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template