普通网友 2013-11-16 13:05
浏览 62
已采纳

在Apache / Nginx设置中刷新输出缓冲区

I would like to have page content for a web page I am developing appear on screen as it is downloaded. In my test/development environment this works as expected using the PHP flush() command.

However, my production setup (WPEngine) uses an Nginx proxy in front of Apache and flush() no longer works (nor do any of the other output buffering commands). I have been able to get the desired behaviour by deliberately filling up the buffer when I want to flush by sending 4k worth of whitespace.

However, that feels like a hack and the page in question needs to be flushed 100 times or more so this adds a considerable amount to the total data downloaded.

Is there a way to signal to Nginx to flush the buffer (or not buffer at all) by sending control characters and/or setting HTTP headers so I can avoid sending otherwise unnecessary whitespace?

Since WPEngine is a managed hosting environment, I am not able to make any changes to the server setup. So, for example, turning off Nginx buffering by adding a directive to the nginx server config is not an option.

The way I am currently doing this is as follows:-

<?php
//turn off server content compression for this page
header('Content-Encoding: none;');

//turn off PHP output buffering
ob_end_flush();

//make padding to fill buffer
$buffer = str_repeat(" ", 4096*8);

$start = time();

do
{
    printf( 'Time: %s secs<br>', time() - $start );
    echo $buffer;
    sleep(1);
} while( (time() - $start) < 10 );
?>
  • 写回答

3条回答 默认 最新

  • dpquu9206 2013-11-17 01:43
    关注

    You should turn off buffering in nginx:

    proxy_buffering off;
    

    Reference: http://nginx.org/r/proxy_buffering

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器