【问题标题】:Perl CGI Output Buffering Using XAMPP Apache Server使用 XAMPP Apache 服务器的 Perl CGI 输出缓冲
【发布时间】:2014-12-14 23:22:36
【问题描述】:

我最近拿起了一本使用 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 缓冲我的输出?谢谢!

【问题讨论】:

  • 包含字符集:print "Content-type: text/plain; charset=utf-8\n\n";
  • @kums: 刚试了一下,没有运气。它仍然需要整整 30 秒才能显示任何内容。
  • 你在其他浏览器上试过了吗?他们表现出相同的行为吗?
  • @kums:它在 Internet Explorer 上的反应相同。不确定 Firefox,我可以尝试安装它,但我认为问题与浏览器无关。

标签: apache perl xampp output-buffering


【解决方案1】:

尝试禁用“mod_deflate”。

只需从启用 mods 的目录中移动/删除它。 这样做后不要忘记重新启动apache。

【讨论】:

  • 我可以尝试移动它,但是在配置文件中包含 mod_deflate 的行已经被注释掉了,所以我怀疑移动它会改变什么。
  • 我移动了 mod_deflate 模块没有运气,输出仍然缓冲,还有其他想法吗?
猜你喜欢
  • 2014-10-13
  • 2011-01-26
  • 2012-10-06
  • 1970-01-01
  • 1970-01-01
  • 2014-03-27
  • 1970-01-01
  • 2023-04-05
  • 2013-10-26
相关资源
最近更新 更多