ob_flush () does not work on my server
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.
php flush not working
You're using ob_flush
without ob_start
, so there is nothing to flush for it.
It also depends on the webserver and proxy and its settings.
You should disable buffering for Nginx (add proxy_buffering off;
to the config file and restart Nginx)
Also, check if your php.ini contains output_buffering = Off
and zlib.output_compression = Off
.
ob_implicit_flush(), flush(), ob_flush() - not working on remote server
I didn't take into account nginx, which has it's own output buffer.
I simply added 'header("X-Accel-Buffering: no");' to the top of the php script and it all works fine now.
PHP flush don't work
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
Related Topics
Utf-8 Safe Equivalent of Ord or Charcodeat() in PHP
Create New Variables from Array Keys in PHP
Single Quotes or Double Quotes for Variable Concatenation
How to Schedule the Execution of a PHP Script on the Server Side
Caching Http Responses When They Are Dynamically Created by PHP
Calculate Difference Between Two Dates Using Carbon and Blade
Destroy PHP Session on Closing
Is It Necessary to Declare PHP Array Before Adding Values with []
Why Are "Echo" Short Tags Permanently Enabled as of PHP 5.4
Sort an Array by a Child Array's Value in PHP
Laravel Eager Loading with Limit
Get Last Insert Id After a Prepared Insert with Pdo
Is It Okay to Use Array[Key] in PHP