Shows a lengthy shell process with Apache

I have a CGI script that takes about 1 minute. Now Apache returns results only to the browser after the process is complete.

How can I make it show output as it was running on the terminal?

Here is an example that demonstrates the problem.

I want the numbers 1 through 5 to be displayed when they are printed.

+5
source share
2 answers

I had to disable mod_deflate so that chunk mode works with apache

I have not found another way for my cgi to turn off automatic encoding for gzip.

+6
source

. , Apache bash - . script:

#!/bin/sh

cat <<END
Content-Type: text/plain

END

for i in $(seq 1 10)
do
    echo $i
    sleep 1
done

-, Apache CGI netcat:

$ nc localhost 80
GET /cgi-bin/chunkit.cgi HTTP/1.1
Host: localhost

HTTP/1.1 200 OK
Date: Tue, 24 Aug 2010 23:26:24 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.7l DAV/2
Transfer-Encoding: chunked
Content-Type: text/plain

2
1

2
2

2
3

2
4

2
5

2
6

2
7

2
8

2
9

3
10

0

, netcat , , .

, Apache, , , , Content-Length; Transfer-Encoding: chunked , script . , script:

chunk () {
    printf '%x\r\n' "${#1}"  # Length of the chunk in hex, CRLF
    printf '%s\r\n' "$1"     # Chunk itself, CRLF
}

chunk $'1\n' # This is a Bash-ism, since it pretty hard to get a newline
chunk $'2\n' # character portably.

, , . Mac OS X 10.5.8 . - Safari, Chrome Firefox 4 , 1000 ( 1024, , - , ). Firefox 3.6 .

, sniffing , . , , , . , ( , HTML ), .

HTML , HTML . , - . , <div> , , . <pre> , Webkit , close, , Firefox . ; , , .

, , . , !

+3

All Articles