在 PHP 中启用输出缓冲来检测用户中止
ignore_user_abort()函数文档中的注释部分表明 PHP 无法检测到用户已中止请求,如果没有数据发送到客户端。对于函数 connection_status()
< 来说,情况确实如此。 /a>,也是。不幸的是,我需要在使用输出缓冲的页面上检测用户中止(可以取消的ajax请求)(并且我不能轻易更改它)。
除了使用该函数之外,还有其他方法可以检测用户中止吗 connection_status()
?或者有什么具体方法可以使该函数返回正确的值? PHP 实际上应该知道请求已中止,因为从客户端收到了 FIN 数据包。
我已经尝试分析流元数据 php://input
、php://output
、php://stdin
和 php://stdout
> 在连接被中止之前和之后以阻塞和非阻塞方式读取/写入数据之后,但这没有提供任何有用的状态更改。
The Notes section in the function documentation of ignore_user_abort() suggest that PHP cannot detect that a user has aborted the request if no data is sent to the client. This is true for the function connection_status()
, too. Unfortunately, I need to detect a user abort (an ajax request that can be cancelled) on a page which makes use of output buffering (and I cannot change that easily.)
Is there any other way of detecting a user abort except using the functionconnection_status()
? Or any specific way to make that function return the correct value? PHP should actually know that the request was aborted, since a FIN
packet is received from the client.
I have already tried analyzing the stream metadata of php://input
, php://output
, php://stdin
and php://stdout
after reading/writing data in a blocking and non-blocking manner before and after the connection was aborted, but that didn't provide any useful state changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
愚蠢的建议,但是......您是否尝试过向客户端发送一些数据,然后在开始输出缓冲之前发送
flush()
?我能想到的唯一其他解决方案是转义缓冲区,但我可以想象它会非常麻烦,正如您所说。也许是一个帮助破坏缓冲区的助手......
如果您已经实现了深度,则可以用一些东西来解释您已实现的缓冲区的深度。
Silly suggestion, but ... have you tried sending some data to the client, followed by a
flush()
before you start the output buffering? The only other solution I can think of is to escape the buffer(s), but I can imagine how it could be quite troublesome, as you said.Maybe a helper to assist with breaking the buffer ...
with something to account for the depth of buffers you've implemented, if you have implemented depth.