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

yipeiwu_com6年前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);

相关文章

php获取域名的google收录示例

复制代码 代码如下: function get_index($domain){ $url="http://www.google.com/search?source=hp&biw=1440...

PHP中in_array函数使用的问题与解决办法

先介绍一下需求背景: 发票方式: 0=捐赠(不要问我为什么,历史原因) 1=对中寄送 2=索取 3=电子发票 现在要对用户提交的数据进行检测: php;auto-links:fals...

PHP实现通过Luhn算法校验信用卡卡号是否有效

本文实例讲述了PHP实现通过Luhn算法校验信用卡卡号是否有效的方法。分享给大家供大家参考。具体实现方法如下: $numbers = "49927398716 49927398717...

php中如何防止表单的重复提交

复制代码 代码如下:<?php/* * php中如何防止表单的重复提交 */session_start();if (empty($_SESSION['ip'])...

php通过asort()给关联数组按照值排序的方法

本文实例讲述了php通过asort()给关联数组按照值排序的方法。分享给大家供大家参考。具体分析如下: php通过asort()给关联数组按照值排序,和sort的区别是,sort为数组中...