ubuntu apache2 cgi 输出缓冲

use*_*728 5 apache ubuntu perl buffering

我在 Ubuntu(11.04 和 12.04)上的 apache2 缓冲所有 cgi 输出直到脚本终止时遇到问题。如果我在 Centos/rhel 6.2 apache2 上运行相同的脚本,它运行正常。

#!/usr/bin/perl

$|=1;
print "Content-type: text/html\r\n\r\n";

print "hi..";
sleep 1;
print "hi..";
sleep 1;
print "hi..";
sleep 1;
Run Code Online (Sandbox Code Playgroud)

我已经验证 mod_deflate 已禁用。

另外,这不仅仅是一个 perl 的事情,用 bash 编写的相同的 cgi 脚本在 Ubuntu VS centos/rhel 上的行为是相同的。

小智 1

我在Solaris 10上遇到了类似的问题,但发现这实际上不是apache的问题,而是Web浏览器(firefox 15.0.1)的问题。(我可以用telnet webserver 80纯 HTML 来验证这一点,响应显示输出确实没有缓冲)

我可以通过打印带有 Content-Type 元标记的标头来解决 Firefox 的问题:

print<<'_EOF_';
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
_EOF_
Run Code Online (Sandbox Code Playgroud)

然而,资源管理器似乎仍然在渲染页面之前等待所有数据,而我没有其他浏览器可用。