header - PHP buffer why \r\n -


i have few conceptual questions (all related, think) regarding following script, @ comments. script works fine.

<?php ob_start();  // create string overflow browser buffer ...? $buffer = str_repeat(" ", 4096);  // indicate new header / html content ...? $buffer .= "\r\n<span></span>\r\n";  ($i=0; $i<5; $i++) {   echo $buffer.$i;   ob_flush();   flush();   sleep(1); }  ob_end_flush(); ?> 

first, why need send \r\n<tag>\r\n browser? assume has headers.

second, why need html in middle?

third, there many examples use 256 bytes instead of 4096. however, script doesn't work if use 256. these examples outdated, , number change again in future?

//edit regarding source links

this code gathered commentary in php.net sleep() function , the solution question. neither mentions why include \r\n.

//edit regarding headers

if don't add \r\n, html tag, , second set of \r\n, script not execute in chrome or safari (it dumps values @ once).

additionally, if called before session_start(), throws error: "cannot send session cache limiter - headers sent".

first, why need send \r\n<tag>\r\n browser? assume has headers.

second, why need html in middle?

normally browser have wait until have fetched whole response until can rendered (just think of xml can valid until last character). since make bad user experience, browsers start parse , render contents possible.

and here html fragment initiator browser build dom , start rendering.

third, there many examples use 256 bytes instead of 4096. however, script doesn't work if use 256. these examples outdated, , number change again in future?

as manual hints there might further buffering incorporated in web server, might attempt overflow buffers flushed in order have expected effect.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -