I'm trying to get PHP flush working for 2 hours, i can't make it work, in localhost it work, but when i drag it on server it stop working. The code is this:
<?php
ob_implicit_flush(true);
ob_end_flush();
for ($i=0; $i<5; $i++) {
echo $i.'<br>';
sleep(1);
}
?>
I tried a lot of other versions, but all the version i fond work only on localhost (as this), but not on my server, i read somewhere that it would be fixed changing some lines on the php.ini file, but i'm using an Aruba hosting windows domain, so i can't edit the php.ini, how can i do?
Update: I tried it on others two free hosting serice, and it work on them, it's just my main hosting services that do problem: what can it be?
Update: Since a lot of script i found use ini_set I tried to check values that they set, i don't know if they can be useful:session.use_trans_sid 0 output_buffering 4096 zlib.output_compression Off
This works, but only in a default apache environment:
<?php
ini_set('output_buffering', 0);
ini_set('zlib.output_compression', 0);
if( !ob_get_level() ){ ob_start(); }
else { ob_end_clean(); ob_start(); }
for ($i = 0; $i < 10; $i++) {
//For Nginx we have to reach minimum buffer size,
//so if it is not enough increment output
echo str_pad( $i . '<br>', 1024 + 10, ' ', STR_PAD_RIGHT );
flush();
ob_flush();
sleep(1);
}
Nginx needs more configurations:
usually in /etc/nginx/nginx.conf
gzip off;
proxy_buffering off;
fastcgi_buffer_size 1k; #set buffer to 1k
fastcgi_max_temp_file_size 0;
fastcgi_buffers 128 1k; #set max buffer size to 1k + 128*1k
Try
<?php
ini_set('session.use_trans_sid', 0);
ob_implicit_flush(true);
ob_end_flush();
for ($i=0; $i<5; $i++) {
echo $i.'<br>';
sleep(1);
}
?>