浏览器关闭后,能继续执行的php函数(ignore_user_abort)_php技巧

WBOY
Release: 2016-05-17 09:10:03
Original
862 people have browsed it

多的不说,直接上代码:

复制代码 代码如下:

ignore_user_abort(true); //设置客户端断开连接时是否中断脚本的执行
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$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);
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