title: Flush output buffer in Apache/Nginx setup
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>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.</p>
  
  <p>The way I am currently doing this is as follows:-</p>
  
  <pre><code>&lt;?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&lt;br&gt;', time() - $start );
      echo $buffer;
      sleep(1);
  } while( (time() - $start) &lt; 10 );
  ?&gt;
  </code></pre>