1

我如何检测 php 中的客户端断开连接。我有一个使用 nusoap 库的 Web 服务,我想检测 Web 服务客户端断开连接。我尝试使用此代码:

ignore_user_abort(true);            // Continue running the script even when the client aborts/disconnects
ob_flush();
flush();                           // Clean PHP's output buffer
usleep(500000);                     
echo "0\r\n\r\n"; 
ob_flush();                         // Clean output buffer
flush();                            // Clean PHP's output buffer
if(connection_aborted() != 0) {     
        //do something
}

它有效,但有两个问题:

  • Flush() 函数添加了导致此警告的附加标头:警告:无法修改标头信息 - 标头已在线发送到 .\lib\nusoap-0_9_5\lib\nusoap.php...
  • 由于我发送 echo "0\r\n\r\n" 以检查客户端连接的附加字符,我的 Web 服务的响应格式不正确。

如何解决上面列出的问题?还有其他方法可以检测 Web 服务客户端断开连接吗?谢谢

4

0 回答 0