简体   繁体   English

ubuntu apache2 cgi输出缓冲

[英]ubuntu apache2 cgi output buffering

I'm having problems with apache2 on Ubuntu ( 11.04 and 12.04 ) buffering all cgi output until the script terminates. 我在Ubuntu(11.04和12.04)上的apache2遇到问题,正在缓冲所有cgi输出,直到脚本终止。 If I run the same script on Centos/rhel 6.2 apache2, it runs normally. 如果我在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;

I have verified that mod_deflate is disabled. 我已验证mod_deflate已禁用。

Also, it's NOT just a perl thing, the same cgi script written in bash behaves the same on Ubuntu VS centos/rhel. 而且,这不仅仅是perl的事情,用bash编写的相同cgi脚本在Ubuntu VS centos / rhel上的行为也相同。

I encountered a similar problem on Solaris 10, but found out, that is was actually not a problem of apache but instead of the web browser (firefox 15.0.1). 我在Solaris 10上遇到了类似的问题,但是发现,实际上这不是Apache的问题,而是Web浏览器(firefox 15.0.1)的问题。 (I could verify this with telnet webserver 80 and speaking plain HTML, the response showed that the output was indeed not buffered) (我可以使用telnet webserver 80并使用纯HTML进行验证,响应表明输出确实没有缓冲)

I could solve this for firefox by also printing a header with a Content-Type meta tag: 我也可以通过打印带有Content-Type元标记的标头来解决此问题。

print<<'_EOF_';
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
_EOF_

Explorer however still seems to wait for all data before rendering the page, other browsers I do not have available. 但是,资源管理器似乎仍然在渲染页面之前等待所有数据,而其他浏览器则无法使用。

The debian/ubuntu ( and solaris too obviously ) apache package stock configs doesn't specify the character set like on Redhat. debian / ubuntu(显然是solaris)的apache软件包标准配置没有像Redhat那样指定字符集。 The real solution is to define simply it. 真正的解决方案是对其进行简单定义。

on ubuntu, add the following to /etc/apache2/httpd.conf 在ubuntu上,将以下内容添加到/etc/apache2/httpd.conf

AddDefaultCharset UTF-8 添加默认字符集UTF-8

Wihtout it, the browser caches the output of the cgi script. 否则,浏览器将缓存cgi脚本的输出。

对我来说,禁用deflate模块有助于:

sudo a2dismod deflate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM