Search code examples
perlapacheubuntubuffering

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. 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.


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.