Is it possible to echo each time the loop is executed? For example:
foreach(range(1,9) as $n){
echo $n."\n";
sleep(1);
}
Instead of printing everything when the loop is finished, I'd like to see it printing each result per time.
Is it possible to echo each time the loop is executed? For example:
foreach(range(1,9) as $n){
echo $n."\n";
sleep(1);
}
Instead of printing everything when the loop is finished, I'd like to see it printing each result per time.
The easiest way to eliminate nginx's buffering is by emitting a header:
This eliminates both
proxy_buffering
and (if you have nginx >= 1.5.6),fastcgi_buffering
. The fastcgi bit is crucial if you're using php-fpm. The header is also far more convenient to do on an as-needed basis.Docs on X-Accel-Buffering Docs on fastcgi_buffering
I found that you can set:
in your php script to disable nginx gzipping without having to modify the
nginx.conf
You need to flush the php's buffer to the browser
See: http://php.net/manual/en/function.flush.php
Easy solution on nginx server:
FINAL SOLUTION
So that's what I found out:
Flush would not work under Apache's mod_gzip or Nginx's gzip because, logically, it is gzipping the content, and to do that it must buffer content to gzip it. Any sort of web server gzipping would affect this. In short, at the server side, we need to disable gzip and decrease the fastcgi buffer size. So:
In php.ini:
. output_buffering = Off
. zlib.output_compression = Off
In nginx.conf:
. gzip off;
. proxy_buffering off;
Also have this lines at hand, specially if you don't have acces to php.ini:
@ini_set('zlib.output_compression',0);
@ini_set('implicit_flush',1);
@ob_end_clean();
set_time_limit(0);
Last, if you have it, coment the code bellow:
ob_start('ob_gzhandler');
ob_flush();
PHP test code:
Related:
php flush not working
How to flush output after each `echo` call?
PHP flushing output as soon as you call echo
I had a gzip problem comming from my php-fpm engine. this code is the only one working for me :
This is my test function : it checks max_execution_time :