打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
如何在用户中止了浏览器之后,让php程序继续运行?
标题: 忘了,问一下:如何在用户中止了浏览器之后,让php程序继续运行? [打印本页]

作者: spiceboy     时间: 2006-4-6 17:36     标题: 忘了,问一下:如何在用户中止了浏览器之后,让php程序继续运行?

有个参数什么的吧。
是什么参数啊?


作者: 北京野狼     时间: 2006-4-6 17:40


作者: spiceboy     时间: 2006-4-6 17:47

不用回了。
知道了。
ignore_user_abort
作者: 北京野狼     时间: 2006-4-6 17:58

你再好好想想。
作者: spiceboy     时间: 2006-4-6 18:00

就是它啊。还想啥?
算了,不跟你说话,你肯定又打算钻我牛角尖。
可我需要的就是这个。
作者: 北京野狼     时间: 2006-4-6 18:04

应该说您自己的牛角太大不用钻。  你总是不考虑清楚就出来发表意见, 那就不要抱怨。这不是好态度。

你需要的不是这个。

[ 本帖最后由 北京野狼 于 2006-4-6 18:05 编辑 ]
作者: spiceboy     时间: 2006-4-6 18:12

好好。
我需要的不是这个。
不是这个。。。。。
我再去重新找。
作者: 北京野狼     时间: 2006-4-6 18:15

服务器如何知道用户中止了浏览器 ?
作者: spiceboy     时间: 2006-4-6 18:19

别急啊
我不是正在找吗
找到了再告诉你。
作者: 北京野狼     时间: 2006-4-6 18:26

找到之后,别忘了通知官方更新一下http协议
作者: spiceboy     时间: 2006-4-6 19:20

好的,没问题。
作者: yzmxf     时间: 2006-4-6 19:24

呵呵

感觉没有可能
作者: 韩三普     时间: 2006-4-6 23:59

这个功能要配置Apache实现。当你关了浏览器,apache仍然会做为进程工作,我曾经用这个功能,抓过几G的图片
作者: spiceboy     时间: 2006-4-7 00:02

那楼上的你改http协议了没?
作者: achieverain     时间: 2006-4-7 00:05

曾经讨论过这个问题。你找一下老帖子
作者: mike519     时间: 2006-4-7 00:32

北京野狼 有个性

spiceboy  还没明白怎么回事啊
作者: 北京野狼     时间: 2006-4-7 09:45

其实与http协议和apache没什么关系。 你想想qq, 等客户端软件, 断网了服务器能立刻知道吗?

只要客户端发出请求,服务器都是执行完了再说。
作者: wobushiwo     时间: 2006-4-7 11:17

当一个请求完了,服务器和客户端之间就不存在状态了

比如 客户端请求,服务端因为什么事响应太慢,这时突然关掉浏览器或点“停止”

或是服务器在给客户端发送数据时,执行了上面的操作,服务器才能知道

总而言之,要捕抓到这一动作,除非是两者在通信时发生的事情

跟HTTP协议没关系,这是socket层面的,它只是规范信息传递的格式
作者: wobushiwo     时间: 2006-4-7 11:19

好像有点跑题了。。。

QUOTE:
如何在用户中止了浏览器之后,让php程序继续运行?
一个完整的请求过去,服务器就会跑完这个请求了啊。。。
作者: 网络混混     时间: 2006-4-7 11:46

register_shutdown_function
作者: spiceboy     时间: 2006-4-7 13:13

carlos at fischerinformatica dot com dot br
31-Jan-2002 10:58
Very very useful!
I was building a chat and I wanted my script to detect when the browser was closed, so the user could be deleted from the online_users table.

<?
echo str_repeat(" ",300);
ignore_user_abort(true); //this way, the user can stop the output, but not the script.
while (true) {
         echo "test<br>\n";
         flush();
         sleep(2);
         if (connection_status()!=0){
                 include (‘dbconnect.inc‘);
                 $sql="delete from online_users where online_user=$user";
                 $sql_exec=pg_exec($vChatDB, $sql);
                 die(); //kills the script
         }
}
?>
作者: 北京野狼     时间: 2006-4-7 13:16



I was building a chat and I wanted my script to detect when the browser was closed
如果你也做聊天室,可以考虑。
作者: spiceboy     时间: 2006-4-7 13:28

<superspice AT yeah.net> wrote:

vi ignore.php

<?php
Set_Time_Limit(0);
ignore_user_abort(true);
echo "begin, please close or stop your browser in 10 seconds\n";
sleep(10);
touch("test.txt");
echo "end";
?>
I browsed ignore.php with my browser, 10 seconds later, test.txt was created.
Then I deleted "test.txt",  refreshed this page and closed it within 3 seconds.
After a few seconds, "test.txt" was created as before.

It showed me the case that the aborting of users‘ browsing had been ignored.
作者: spiceboy     时间: 2006-4-7 13:32

I wrote a simple function that can "spawn" another thread within the webserver by making async http request. The page that is being spawned can call ignore_user_abort() and do whatever it wants in the background...

<?php

   function http_spawn($page)
   {
       $basepath=ereg_replace(‘[^/]*$‘, ‘‘, $_SERVER[‘PHP_SELF‘]);
       $cbSock=fsockopen(‘localhost‘, $_SERVER[‘SERVER_PORT‘], $errno, $errstr, 5);
       if ($cbSock)
       {
           fwrite($cbSock, "GET {$basepath}{$page} HTTP/1.0\r\n"
               ."Host: {$_SERVER[‘HTTP_HOST‘]}\r\n\r\n");
       }
   }
?>

Example:
<?php

   if ($search_initialized)
       http_spawn("ftindex.php");
?>
作者: spiceboy     时间: 2006-4-7 13:41



<?php
ignore_user_abort(true);
// 1.1 处理用户提交数据
$Adodb->StartTrans();
    .........................
    .........................
$Adodb->CompleteTrans();

/* 用户可能在1.1执行完成后,而2.1没有执行前的此处关闭浏览器或死机? */

// 1.2 处理另一部分数据
$Adodb->StartTrans();
    .........................
    .........................
$Adodb->CompleteTrans();

// 1.3 校验整个数据的一致性和完整性,并写错误日志
   dosomething();
?>
当一个页面里放置了2个或2个以上的事务操作。需要这个页面不被中断。以保持数据的一致性。
作者: 北京野狼     时间: 2006-4-7 13:54

你真好有趣啊, 还是再想想吧

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
炒股必看三十图(箱体篇、量能篇)A
PHP 常用的header头部定义
php php ignore_user_abort
使用浏览器缓存来加快站点的访问速度
VBA入库单改进版(窗体录入的完美例子)
用 PHP 获得浏览器信息?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服