我最近选择了一本带有Perl书的CGI编程,在尝试测试其中一个示例问题时遇到了一个问题。根据该书的新版本Apache(自v1.3起)默认情况下不缓冲CGI脚本的输出,但是当我运行下面的脚本时,它会等到整个循环完成后再打印任何内容:
# count.cgi
#!"C:\xampp\perl\bin\perl.exe" -wT
use strict;
#print "$ENV{SERVER_PROTOCOL} 200 OK\n";
#print "Server: $ENV{SERVER_SOFTWARE}\n";
print "Content-type: text/plain\n\n";
print "OK, starting time consuming process ... \n";
# Tell Perl not to buffer our output
$| = 1;
for ( my $loop = 1; $loop <= 30; $loop++ ) {
print "Iteration: $loop\n";
## Perform some time consuming task here ##
sleep 1;
}
print "All Done!\n";
这本书说使用旧版本的Apache你可能需要将脚本作为“nph”脚本运行,因此输出不会被缓冲,但我甚至试过没有运气。
# nph-count.cgi
#!"C:\xampp\perl\bin\perl.exe" -wT
use strict;
print "$ENV{SERVER_PROTOCOL} 200 OK\n";
print "Server: $ENV{SERVER_SOFTWARE}\n";
print "Content-type: text/plain\n\n";
print "OK, starting time consuming process ... \n";
# Tell Perl not to buffer our output
$| = 1;
for ( my $loop = 1; $loop <= 30; $loop++ ) {
print "Iteration: $loop\n";
## Perform some time consuming task here ##
sleep 1;
}
print "All Done!\n";
我正在运行:Apache / 2.4.10(Win32)OpenSSL / 1.0.1i PHP / 5.5.15
很明显,这个版本的Apache超出了v1.3,所以这里发生了什么?我做了一些研究,发现如果你启用了“mod_deflate”或“mod_gzip”,它可以导致输出被缓冲,但我检查了我的配置文件,“mod_deflate”和“mod_gzip”都已被禁用。我看到的关于缓冲的所有其他帖子都引用了PHP并说要修改“php.ini”,但我使用的是Perl,而不是PHP,所以这似乎不是解决方案。
此外,我不知道这是否有帮助,但我使用Chrome作为我的网络浏览器。
如何阻止Apache缓冲输出?谢谢!
答案 0 :(得分:0)
尝试禁用'mod_deflate'。
只需从启用mods的目录中移动/删除它。 这样做之后别忘了重启apache。