zoukankan      html  css  js  c++  java
  • 怎样判断用户已经掉线,关闭网页

    仔细研究了

    connection_status 和 connection_aborted

    了解清楚他们的用法:

    <?
    echo str_repeat(" ",300);
    ignore_user_abort(true); //没有这个一旦用户断线,php(线程)就会立即终止!没有机会执行" if  connection_status()!=0||connection_aborted){"了

    while (true) {
            

             echo "test<br>/n;//必须有输出, 否则线程会一直执行下去,直到你重新启动apche(2小时以上,我只测了那么久),输出也可以写道 //注释2处

             flush();
             
             if (connection_status()!=0||connection_aborted()){
                     //用户退出了

             }

             //注释2

             sleep(2);
    }
    ?>

    本来想给php手册加个注释的,无奈,始终加不上,他那个验证问题,我试了用数字和大小写英文回答,始终都没有对,郁闷死我了!

    <?
    echo str_repeat(" ",300);
    ignore_user_abort(true); //without this, current apache thread will terminate Immediately,so the code "if (connection_status()!=0){" will not be executed as the script was broken off!
    while (true) {
             echo "test<br>/n";//if there's no any output, this script will execute endless, which means the current apache thread will not end until you restart apache and connection_status()will keep 0 and connection_aborted() will keep false.
             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
             }
    }
    ?>

  • 相关阅读:
    Visual Studio for Application 内幕之二(转载)
    查找数组中极值
    .net中HashTable的最大容量
    返回数组中所有元素被第一个元素除的结果
    将json转换为DataTable
    ASP.NET面试题(推荐_有答案) FX
    [转]U盘启动制作工具|大白菜启动制作工具
    使用QFileDialog 同时选择 文件和文件夹
    [转]如何用SQL命令修改字段名称
    小朋友 老师 笑话
  • 原文地址:https://www.cnblogs.com/lein317/p/5067655.html
Copyright © 2011-2022 走看看