dourui7186 2017-05-20 22:56
浏览 163

使用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.

  • 写回答

1条回答 默认 最新

  • dongyong8098 2019-05-23 12:49
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?