This function works perfectly on my other server and locally on my pc showing every second the numbers, but when I send the cloud code from my client it only shows the results after the page loads 100%.
It works correctly here: http://kicklaunch.me/buffer.php
In this only when the page loads completely: http://raio.adm.br/buffer.php
Both servers have the same PHP version 5.4.45
<?php
for($i=0; $i<20; $i++) {
echo 'printing...'."<p>";
ob_flush();
flush();
sleep(1);
}
?>
SOLUTION
output_buffering = Off
ob_implicit_flush(1);
for($i=0; $i<10; $i++){
echo $i;
//this is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
sleep(1);
}
As you have mentioned that you don't see any value for output_buffering
in your comment, I assume it's turned off in your server.
If you are using your own server, then look for the Configuration File (php.ini) Path
option in your phpinfo
page (which I asked you to create in comments).
Then open that file, find the ;output_buffering = Off
line, and change it to:
output_buffering = 4096
You might need to restart your apache server (or your web server if it's different).
=============================================================
If you are on a shared hosting, most hosting providers allow you add your own configurations by adding a php.ini
file to your public_html
folder.
Create a file named as php.ini
and include output_buffering = 4096
in it, then upload it to your public_html
folder. It should work.
Hope it helps :) Feel free to ask anything if you have any doubts.