Strange PHP output buffering

Posted by radek-k on Server Fault See other posts from Server Fault or by radek-k
Published on 2011-01-03T19:32:56Z Indexed on 2011/01/03 19:55 UTC
Read the original article Hit count: 224

Filed under:

PHP:

header('Content-type: text/plain');

for ($i=0; $i<10; $i++){
  echo "$i\r\n";
  ob_flush();
  flush();
  sleep(1);
}

I tried script above on 2 different servers. Both respond numbers 0...9 in every line. In case of first server each number is received every second. In case of second server there is no output for 10 seconds and entire output is displayed at once. What might be wrong int second case? I tried various uutput control Functions but it didn't help.

Set of response headers in both cases is pretty much the same:

HTTP/1.1 200 OK
Date: Mon, 03 Jan 2011 19:21:21 GMT
Server: Apache
X-Powered-By: PHP/5.2.14
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain

© Server Fault or respective owner

Related posts about php