日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php if终止,php判断用户是否掉线及关闭网页的方法分享

發布時間:2023/12/1 php 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php if终止,php判断用户是否掉线及关闭网页的方法分享 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

要實現判斷用戶已掉線并關閉網頁,主要用到方法connection_status 和 connection_aborted。

通過一個例子,來了解下它們的用法:

echo str_repeat(" ",300);

//以下不可省略,否則用戶斷線,php(線程)立即終止,不會執行" if connection_status()!=0||connection_aborted){"

ignore_user_abort(true);

while (true) {

echo "test
/n;//必須有輸出, 否則線程會一直執行下去,直到重新啟動apche(測試過程2小時),輸出也可以寫到//注釋2處

flush();

if (connection_status()!=0||connection_aborted()){

//用戶退出了

}

//注釋2

sleep(2);

//by www.jbxue.com

}

?>

下面是另一個例子:

//檢測是否掉線,然后關閉網頁

//編輯:www.jbxue.com

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
/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

}

}

?>

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的php if终止,php判断用户是否掉线及关闭网页的方法分享的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。