Quoting a different answer:
The HTML5 charset sniffing buffer size is 512 bytes. So the response
needs to either have 512 bytes of padding or set a charset (via
tag or HTTP header).
I can confirm the delayed output happens on Firefox
and Edge
, Chrome
and Opera
output the content immediately, independent of the buffer size.
The code bellow outputs in real-time on all browsers, as long as the str_pad
size is > 1024
(this value can differ from browser to browser)
while (@ob_end_flush());
ob_implicit_flush(true);
echo "first line visible to the browser";
echo str_pad("",1024," "); // try lower values and the "first line" won't be displayed instantly
echo "<br />";
sleep(5);
echo "second line visible to the browser after 5 secs";
php.ini
excerpt:
output_buffering
; Output buffering is a mechanism for controlling how much output data
; (excluding headers and cookies) PHP should keep internally before
pushing that ; data to the client. If your application's output
exceeds this setting, PHP ; will send that data in chunks of roughly
the size you specify. ; Turning on this setting and managing its
maximum buffer size can yield some ; interesting side-effects
depending on your application and web server. ; You may be able to
send headers and cookies after you've already sent output ; through
print or echo. You also may see performance benefits if your server is
; emitting less packets due to buffered output versus PHP streaming
the output ; as it gets it. On production servers, 4096 bytes is a
good setting for performance ; reasons. ; Note: Output buffering can
also be controlled via Output Buffering Control ; functions. ;
Possible Values: ; On = Enabled and buffer is unlimited. (Use with
caution) ; Off = Disabled ; Integer = Enables the buffer and sets
its maximum size in bytes. ; Default Value: Off ; Development Value:
4096 ; Production Value: 4096 ;
http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering
You may want to try
output_buffering = off
But your server performance may suffer.