Home > Backend Development > PHP Tutorial > PHP function that can continue to execute after the browser is closed (ignore_user_abort)_PHP tutorial

PHP function that can continue to execute after the browser is closed (ignore_user_abort)_PHP tutorial

WBOY
Release: 2016-07-21 15:17:00
Original
1237 people have browsed it

Without further ado, let’s go directly to the code:

Copy code The code is as follows:

ignore_user_abort(true); //Set the customer Whether to interrupt the execution of the script when the client disconnects
set_time_limit(0);
$file = '/tmp/ignore_user.txt';
if(!file_exists($file)) {
file_put_contents ($file);
}
if(!$handle = fopen($file,'a+b')){
echo "not open file:".$file;
exit;
}
$i=0;
while($i<100) {
$time = date("Y-m-d H:i:s",time());
echo $ time."n";
if(fwrite($handle,$time."n")===false) {
echo "not write file:".$file;
exit;
}
echo "write file time:".$time."n";
$i++;
sleep(2);
}
fclose($handle);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325782.htmlTechArticleDon’t say much, just go to the code: Copy the code and the code is as follows: ignore_user_abort(true); //Set the client Whether to interrupt the execution of the script when disconnecting set_time_limit(0); $file = '/tmp/ig...
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