普通网友 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 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题