PHP connection_aborted 不适用于 nginx? [英] PHP connection_aborted doesn't work with nginx?

查看:95
本文介绍了PHP connection_aborted 不适用于 nginx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让函数 connection_aborted 与 nginx 一起使用.我用来测试的代码如下:

I can't seem to get the function connection_aborted to work with nginx. The code I used to test is as follow:

<?php
ignore_user_abort(true);
ob_implicit_flush();
$i = 0;
while (!connection_aborted()) {
    echo $i;
    $i++;
    sleep(1);
}
file_put_contents('test',$i);

在 Apache 中,它可以正常工作,但会延迟一点.即当我在3"时按下浏览器上的停止按钮时,测试"文件显示8".这是一个可以接受的余量,但在 nginx 上,它似乎没有向测试"文件输出任何内容.

In Apache, it works correctly, although it delays a little. i.e. When I press stop button on browser when "3", the 'test' file shows "8". That is an acceptable margin, but on nginx, it doesn't seem to output anything to the 'test' file.

推荐答案

检查你的 Nginx 配置,它应该有

Check your Nginx configuration, it should have

fastcgi_ignore_client_abort off;

此配置键默认为 off,因此即使您根本没有 fastcgi_ignore_client_abort,您的脚本也应该按预期工作.

This configuration key has off as the default, so even if you have no fastcgi_ignore_client_abort at all, your script should work as expected.

这篇关于PHP connection_aborted 不适用于 nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆