使用PHP和服务器发送事件(使用proxy_fcgi刷新)

I use Ubuntu 17.04, Apache 2.4, proxy_fcgi, and php-fpm. Everything works and connects nicely, except for flushing for Server Sent Events.

Flushing used to work nicely with mod_fastcgi and fastcgiexternalserver with "-flush". Now with Ubuntu 17.04, it doesn't include mod_fastcgi, and proxy_fcgi is recommended.

With proxy_fcgi I've disabled gzip, output buffering, use "Content-Encoding: none", the only real way for connection_aborted and flush to work is if you send around 32K (I'm guessing this is because of proxy buffering?)

It says in the Apache Docs that you cannot set ProxyReceiveBufferSize or ProxyIOBufferSize less than 512.

There really should be an easier way to do this with proxy_fcgi.

Example code of sending data for Server Sent Events:

while (!connection_aborted() ) {
  echo('data: {}' . PHP_EOL . PHP_EOL);
  flush();
} // While //

Edit: I've tried ob_flush() too, but I disabled Output Buffering (ob_*) with ob_end_clean() previously, and ob_flush() will return an error.

Albeit this question has been asked some years ago, I just ran into a similar problem with Apache 2.4 and mod_fcgid. The PHP application did directly return data without buffering (tested with internal server php -S 0.0.0.0:8080 index.php) - but it was buffered when being used with Apache.

The following configuration disables output buffering for mod_fcgid (default size is 65536 bytes)

FcgidOutputBufferSize 0

https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#FcgidOutputBufferSize