使用XAMPP Apache服务器执行Perl CGI输出缓冲
我最近选择了一本使用Perl书籍的CGI编程,并尝试测试遇到问题时的一个示例问题。根据本书较新版本的Apache(自v1.3以来),默认情况下不缓存CGI脚本的输出,但是当我运行下面的脚本时,它会等到整个循环完成后才打印任何内容:使用XAMPP Apache服务器执行Perl 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";
我运行:阿帕奇/ 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缓冲我的输出?谢谢!
尝试禁用'mod_deflate'。
只需从启用了mods的目录中移动/删除它即可。 不要忘记在这样做后重新启动Apache。
我可以尝试移动它,但在配置文件中包含mod_deflate的行已被注释掉,所以我怀疑移动它会改变任何内容。 – tjwrona1992 2014-10-20 12:48:35
我搬了mod_deflate模块没有运气,输出仍然缓冲,有任何其他的想法? – tjwrona1992 2014-10-21 01:06:52
包括字符集:'print'Content-type:text/plain; charset = utf-8 \ n \ n“;' – kums 2014-10-20 03:24:10
@kums:刚试过,没有运气。它在显示任何内容之前还需要整整30秒。 – tjwrona1992 2014-10-20 03:26:55
你有没有尝试过与其他浏览器?他们显示相同的行为? – kums 2014-10-20 03:29:25