views:

141

answers:

3

I have a small cgi script that fetches and validates a configuration file for Nagios. The typical run time is several minutes, and I would like to get some feedback in the browser during the run.

To illustrate what I would like to happen, consider this:

#!/bin/sh
echo "Content-type: text/plain"
echo

for i in A B C D E
do
        echo $i
        sleep 10
done

When I do a GET on this script via telnet or with wget, the output comes one row at a time, with ten second intervals ("A"... "B"... "C"... and so on).

When I try to open it in a common browser, the browser seems to buffer it all and present the output when the script is done (50 seconds of silence... "ABCDE").

Is it possible to make the browser present the data to the user as soon as it has arrived?

+1  A: 

Use Wireshark.

Jherico
Thanks for the tip, sniffing made me realize that gzip/deflate encoding made the server send the entire output in one packet. After unsetting the Accept-Encoding header, data arrives as several packets. The browser behaviour is however the same - nothing is shown until the connection is closed.
Anders Lindahl
+2  A: 

I believe what you want is to use "html chunk encoding". This lets the server send the browser a "chunk" of HTML that it can start rendering. ASP & ASP.Net take care of this for you whenever you use "Response.Write".

Here are some references:

David
Exactly what I was looking for, thanks David!
Anders Lindahl
A: 

Use Response.Flush() after you have written enough to the response buffer....

http://www.stephanunrau.com/

Stephan

related questions