doushi6932 2014-12-08 08:42
浏览 15

如何在php中检测用户中止连接?

I try to log all requests aborted by users, but I found connection_status() not work as I expected.

<?php
ignore_user_abort(true);
ob_implicit_flush();
//do something
sleep(5);
header('Content-Type: text/json');
echo json_encode($output);
flush();
ob_flush();
if(connection_status() & CONNECTION_ABORTED){
    //log aborted request
}

The client timeout is 2 seconds, and I always got "0" as connection_status().

According to document, connection status will not be checked until script try to output something. So i added flush codes, but it still got "0" as connection_status().

Please help me understand the php connection handler. Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效