PHP檢測用戶是否關(guān)閉瀏覽器的方法
本文實例講述了PHP檢測用戶是否關(guān)閉瀏覽器的方法。分享給大家供大家參考,具體如下:
1、例子1
echo str_repeat(" ",3000);
ignore_user_abort(true);
mylog('online');
while (true) {
/*
* 1、程序正常結(jié)束 connection_status 0
* 2、點擊瀏覽器“停止”按鈕 connection_status 1
* 3、超時 connection_status 2
*/
echo "test<br>\n"; //注意程序一定要有輸出,否則ABORTED狀態(tài)是檢測不到的
flush();
sleep(1);
if (connection_status()!=0){
mylog('offline');
die('end the script');
}
}
function mylog($str)
{
$fp = fopen('e:/abort.txt', 'a');
$str = date('Y-m-d H:i:s').$str."\r\n";
fwrite($fp, $str);
fclose($fp);
}
2.例子2
function foo() {
$s = 'connection_status '. connection_status();
mylog($s);
}
register_shutdown_function('foo');//script processing is complete or when exit() is called
set_time_limit(10);
for($i=0; $i<10000000; $i++)
echo $i;
function mylog($str)
{
$fp = fopen('e:/abort.txt', 'a');
$str = date('Y-m-d H:i:s').$str."\r\n";
fwrite($fp, $str);
fclose($fp);
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP基本語法入門教程》、《PHP錯誤與異常處理方法總結(jié)》及《php常用函數(shù)與技巧總結(jié)》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
PHP ADODB生成HTML表格函數(shù)rs2html功能【附錯誤處理函數(shù)用法】
這篇文章主要介紹了PHP ADODB生成HTML表格函數(shù)rs2html功能,結(jié)合實例形式分析了php使用ADODB類使用函數(shù)rs2html輸出結(jié)果集生成HTML表格相關(guān)操作技巧,并附錯誤處理函數(shù)errorMsg用法,需要的朋友可以參考下2018-05-05
WordPress的文章自動添加關(guān)鍵詞及關(guān)鍵詞的SEO優(yōu)化
這篇文章主要介紹了給WordPress的文章添加關(guān)鍵詞及關(guān)鍵詞的SEO優(yōu)化方法,突出關(guān)鍵詞在搜尋結(jié)果中的作用,需要的朋友可以參考下2016-03-03
memcached 和 mysql 主從環(huán)境下php開發(fā)代碼詳解
一般的大站通常做法是 拿著內(nèi)存當(dāng)數(shù)據(jù)庫來用(memcached). 和很好的讀 寫分離 備份機制 (mysql 的主從) 在這樣的環(huán)境下我們怎么進行PHP開發(fā)呢。2010-05-05
php緩沖 output_buffering和ob_start使用介紹
這篇文章主要介紹了php緩沖 output_buffering和ob_start的相關(guān)資料,需要的朋友可以參考下2014-01-01
PHP 利用Mail_MimeDecode類提取郵件信息示例
重點為one_mail函數(shù)。利用Mail_mimeDecode類從郵件中提取郵件頭和郵件正文,具體實現(xiàn)如下2014-01-01

