Question

I'm having problems with apache2 on Ubuntu ( 11.04 and 12.04 ) buffering all cgi output until the script terminates. If I run the same script on Centos/rhel 6.2 apache2, it runs normally.

#!/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.

Also, it's NOT just a perl thing, the same cgi script written in bash behaves the same on Ubuntu VS centos/rhel.

Was it helpful?

Solution

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). (I could verify this with telnet webserver 80 and speaking plain HTML, the response showed that the output was indeed not buffered)

I could solve this for firefox by also printing a header with a Content-Type meta tag:

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.

OTHER TIPS

The debian/ubuntu ( and solaris too obviously ) apache package stock configs doesn't specify the character set like on Redhat. The real solution is to define simply it.

on ubuntu, add the following to /etc/apache2/httpd.conf

AddDefaultCharset UTF-8

Wihtout it, the browser caches the output of the cgi script.

For me it helps to disable the deflate module:

sudo a2dismod deflate
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top