我的网站上有一个以彗星为主导的聊天脚本
我的服务器配置是使用PHP-FPM的NGINX,我也在不同的端口上安装了apache。
当我尝试在Apache上运行聊天脚本时,当我用1024个字符填充缓冲区时,我会对缓冲区进行泛洪(我的输出缓冲大小为1 KB),它会自动刷新它在apache中。
但是在nginx中却没有。
我的代码与此非常相似
<?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,
有没有办法避免在nginx中缓冲,我在stackoverflow中搜索了很多但是我无法达成解决方案
请注意:我不想在我的所有php配置中关闭缓冲我只想在聊天脚本中发生这种情况
答案 0 :(得分:6)
升级你的nginx服务器{} config:
fastcgi_keep_conn on; # < solution
proxy_buffering off;
gzip off;