当连接中止时,我尝试在会话上标记一个值,但是 php 函数 connection_status() 无法正常工作!下面是代码:
1 没有 while 语句:
session_start();
ignore_user_abort(true);
ob_end_clean();
echo 'Testing'; //test if it has output to the browser
flush();
sleep(7);
echo "test";
flush();
if (connection_status() != CONNECTION_NORMAL){
$_SESSION['conn']='failed'; //never called
}
2 WITH while 语句:
session_start();
ignore_user_abort(true);
ob_end_clean();
echo "Testing connection handling";
while (1) {
if (connection_status() != CONNECTION_NORMAL){
$_SESSION['conn']='failed'; //worked at some time
break;
}
sleep(1);
echo "test";
flush();
}
当我使用这些代码进行测试时,我在代码执行结束之前手动中止了连接。但是第一个代码在我m excepted(do not mark assign 'failed' to the session) , and the second code works.
Why the first dosen
工作时不起作用?!