如何使用彗星(在nginx中禁用输出缓冲,它在apache中正常工作,但在nginx中不起作用)? [英] How to use comet (disable output buffering in nginx, it works in apache normally but not nginx)?

查看:98
本文介绍了如何使用彗星(在nginx中禁用输出缓冲,它在apache中正常工作,但在nginx中不起作用)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个彗星驱动的聊天脚本

I have a comet-driven chat script in my site

我的服务器配置是带有PHP-FPM的NGINX,我还在其他端口上安装了apache.

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

当我尝试在Apache上运行聊天脚本时,当我用1024个字符填充缓冲区时,我确实填充了缓冲区(我的输出缓冲大小为1 KB),它将自动刷新.这在Apache中.

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.

但是在nginx中却没有.

But in nginx it doesn't.

我的代码与此非常相似

<?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

}


?>

在我的Nginx配置中,我关闭了gzip,关闭了proxy_buffering,

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

有没有一种方法可以避免在nginx中进行缓冲,我在stackoverflow中搜索了很多内容,但找不到解决方法

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

,请注意:我不想在所有php配置中关闭缓冲,我只是希望在聊天脚本中发生这种情况

推荐答案

升级您的nginx服务器{}配置:

Upgrade your nginx server {} config:

fastcgi_keep_conn on; # < solution

proxy_buffering off;
gzip off;

这篇关于如何使用彗星(在nginx中禁用输出缓冲,它在apache中正常工作,但在nginx中不起作用)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆