title: PHP GZip and Server Sent Event Streams
body: <p>I'm writing a <a href="http://www.w3.org/TR/eventsource/" rel="nofollow">server sent event</a> stream in PHP and I receive the error:</p>
  
  <blockquote>
    <p>"failed to flush buffer zlib output compression"</p>
  </blockquote>
  
  <p>This I believe is due to trying to flush the gzipped output.</p>
  
  <p>Here's my PHP code:</p>
  
  <pre><code>header ("Content-Type: text/event-stream\n\n");
  header ("Cache-Control: no-cache");
  
  echo "data: {$json}";
  echo "\n\n";
  
  ob_flush(); // ERROR HERE
  flush();
  </code></pre>
  
  <p>My question is what is the best way to get this working - ideally without disabling gzip in apache - can it be turned off in PHP?</p>
  
  <p>I tried this but it didn't work:</p>
  
  <pre><code>if(ini_get('zlib.output_compression')){
      ini_set('zlib.output_compression', 'Off');
  }
  </code></pre>