Question: Years ago I wrote CGI programs at previous jobs that relied on progressive rendering, since those CGI programs could take a long time (minutes) to run, producing a line of output approx every second. I find that today, I cannot get progressive rendering to occur even with the simplest example.

I've seen a lot of suggestions on this topic about where to put CSS, scripts, etc. However, the trivial example below has none of that.

I don't see anywhere where browsers have an option to affect progressive rendering. I have tried this on several systems/devices with several browsers (chrome, firefox, opera), all with the same result.

Below is a trivial example that I expect to produce some output every 2 seconds, but instead it renders when the whole document is complete.
Am I missing something obvious?

```
#!/usr/bin/env perl

select(STDOUT); $| = 1;     # don't buffer stdout

print "Content-Type: text/html\; charset=ISO-8859-1\n\n" ;
print "<html> <head> <title> Testing </title> </head> <body>\n" ;

my $message = "<code>" .
    "Why doesn't this render immediately? <br>\n" x 5 .
    "</code>\n" ;

for ( my $i=0 ; $i < 5 ; $i++ ) {
    print "$message\n" ;
    sleep(2) ;
}
print "</body></html>\n" ;

```

Answer: 
The response from ccm didn't work for me, but it set me on the right track to find the problem. The solution was to add the following to my Apache config:

```
SetEnvIfNoCase Request_URI \.cgi$ no-gzip dont-vary

```

which I found from [Prevent output buffering with PHP and Apache](https://stackoverflow.com/questions/15028587/prevent-output-buffering-with-php-and-apache)

While trying out what @ccm suggested, it appears the buffer size is 1K, which is fine with me.

Thanks a huge amount to @ccm for setting me on the right path!
You also need your webserver to keep the CGI script running long enough. A default Apache has a 1 minute [timeout](https://httpd.apache.org/docs/2.4/mod/core.html#timeout). 

You already turned off buffering with `$_`, which is fine. There is no more control you can have from the script. The connection needs to stay open, even if you want to do chuncked transfer, which isn't really needed in your example.

It's the server who shuts it down after a while. And once the connection is gone the webserver doesn't send the remainder of your response over the wire because that connection is gone and the CGI handle is detached, so nothing is reading your output to pass it along.

Conclusion: **Set the timeout to a higher value.** 

Anecdote: I used to work on a system with a timeout setting of about an hour, where a CGI based back office application did large DB queries over a huge MySQL database and stuff took long. People who worked with that tool typically started it and went to grab coffee or have lunch.