How to use comet (disable output buffering in nginx, it works in apache normally but not nginx)?

蓝咒 提交于 2020-01-05 07:08:10

问题


I have a comet-driven chat script in my site

My Servers configuration is NGINX with PHP-FPM , I also have apache installed on different port.

When I try to run the chat script on Apache and I do flood the buffer ( my output buffering size is 1 KB) when I flood it with 1024 character, it flushes automatically That's in apache.

But in nginx it doesn't.

My code is very similar to this

<?php

// this is to fill the buffer and start output; and it works on apache normally
echo str_repeat(" ",1024); 


while($condition){

  // Some code here...
  $messages = getMessagesFromDatabase();

 if($messages){
  echo "output";   // output works on apache but not nginx
  flush();
  ob_flush();
 }

 usleep(500000); // 0.5 Second

}


?>

in my nginx configuration i turned gzip off, proxy_buffering off,

is there a way to avoid buffering in nginx, I searched a lot here in stackoverflow but I couldn't reach to a solution

and please notice: I don't want to turn off buffering in all of my php configuration I just want this to happen in the chat script


回答1:


Upgrade your nginx server {} config:

fastcgi_keep_conn on; # < solution

proxy_buffering off;
gzip off;


来源:https://stackoverflow.com/questions/12404469/how-to-use-comet-disable-output-buffering-in-nginx-it-works-in-apache-normally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!