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

yipeiwu_com5年前PHP代码库
多的不说,直接上代码:
复制代码 代码如下:

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<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);

相关文章

Yii框架调试心得--在页面输出执行sql语句

Yii框架调试心得--在页面输出执行sql语句

我们使用:yiidebugtb来调试(因为用他界面比较美观,不影响界面其他元素)。 1.下载yiidebugtb,并且放入到 application.extensions.yiidebu...

PHP中函数gzuncompress无法使用的解决方法

前言 gzuncompress函数不是php自带的系统函数而是一个插件函数了所以要使用 gzuncompress函数我们必须安装一个插件,下面来看看PHP函数gzuncompress无法...

php禁止直接从浏览器输入地址访问.php文件的方法

本文实例讲述了php禁止直接从浏览器输入地址访问.php文件的方法。分享给大家供大家参考。具体实现方法如下: 一般来说对于有些重要的文件我们并不希望用户可以直接输入地址进行访问,对此我们...

php下过滤HTML代码的函数

具体如下所示: /*---------------------- 过滤HTML代码的函数 -----------------------*/ function htmlEnco...

PHP curl_setopt()函数实例代码与参数分析

curl_setopt (PHP 4 >= 4.0.2) curl_setopt -- 为CURL调用设置一个选项 描述   bool curl_setopt (int ch, s...