PHP ob_flush flush buffers an invalid solution in ie

  • 2020-03-31 20:39:53
  • OfStack

Buffering of PHP programs, regardless of the circumstances under which PHP is executed (CGI, web servers, and so on). This function sends all the output of the current program to the user's browser.
The flush() function does not affect the caching mode of the server or client browser. Therefore, you must flush the output buffer using both the ob_flush() and flush() functions.
Individual web server programs, especially those under Win32, still cache the output of the script until the program ends before sending the result to the browser
I wrote a small example to output a number every second on the page.

According to the online code:
 
ob_end_clean(); 
for ($i=10; $i>0; $i--) 
{ 
echo $i; 
flush(); 
sleep(1); 
} 


Or:
 
for ($i=10; $i>0; $i--) 
{ 
echo $i; 
ob_flush(); 
flush(); 
sleep(1); 
} 


I found that it worked in firefox, but not in IE. It was always 10 Numbers at a time, which means the buffer didn't work.

I started to adjust the Settings of output_buffering in php.ini and restart apache, which was still invalid.

And then I saw this:

Some versions of Microsoft Internet Explorer don't display the page until after 256 bytes have been received, so you have to send some extra space for these browsers to display the page content.

The problem with the evil Internet explorer is that there's so much fucking going on!

Then I modified the program and it worked:
 
echo str_pad('',4096); 
for ($i = 0; $i < 10; $i++) { 
echo $i; 
ob_flush(); 
flush(); 
sleep(1); 
} 

 
//ob_end_flush();//IE8 It didn't work  
echo str_pad(" ", 256);//IE needs to receive 256 bytes before it starts to display

for($i=0;$i<18;$i++) { 
echo $i; 
flush(); 
sleep(1); 
} 

Related articles: