怎样判断用户已经掉线,关闭网页
2009-07-22 18:59
375 查看
仔细研究了
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
}
}
?>
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
}
}
?>
相关文章推荐
- 怎样判断用户已经掉线,关闭网页
- 怎样判断用户已经掉线,关闭网页
- javascript:如何判断一个网页被用户关闭
- 如何判断一个用户是关闭、还是刷新网页
- 通过文件锁实现,程序开始运行时,先判断文件是否存在,若存在则表明该程序已经在运行了,如果不存在就用open函数创建该文件,程序退出时关闭文件并删除文件。
- 如何判断注册用户是否已经存在(membership验证)
- linux怎样判断当前登录的用户是从console登录还是telnet登录的
- 今天写出的一个基类。用于根据cookies来判断用户是否已经登陆
- 用JS在IE和火狐下判断网页是刷新还是关闭
- 谈一下怎样判断网页是静态的还是伪静态的?
- 在 JavaScript 中判断用户是用手机还是电脑打开此网页
- 怎样把已经做好的网页传到网上去?
- 怎样判断一个一个控件是否已经销毁
- 判断用户是否已经登陆域的注册表键值
- 在完成端口IOCP模型判断客户端是否已关闭连接(掉线)
- magento -- magento中如何判断一个用户是否已经登陆
- javascript判断网页是关闭还是刷新
- Django中的模版文件--index.html(判断用户是否已经登录)
- TCP服务器端怎么判断客户端已经关闭了连接?
- discuz 对不起,当前站点已经关闭了用户多应用服务