On my development server (CentOS 6.3, PHP 5.3) this works fine:
ignore_user_abort(true);
header('Location: http://test.hooshmarketing.com/tools/test/test_pretty_output.php');
//here a long script keeps executing in the background a few seconds
this works fine too
ob_implicit_flush(true);
echo "foo"; //I see foo on the browser and...
sleep (15);
echo "bar"; //... about 15 seconds later I see bar on the browser
and this
ob_start();
echo "foo"; //foo is written...
sleep(10);
ob_flush(); //...about 10 second later, foo is sent
echo "bar"; //bar is written...
sleep(10);
ob_end_flush(); //...about 10 second later, bar is sent
On my contractor's production server (bluehost PHP 5.2 shared hosting) none of the three examples work. Nothing is sent to the client until the script finishes executing. I tried setting ini_set('output_buffering', '0')
and output_buffering = Off
on the script folder's php.ini file but no luck. Any ideas on why this could be happening?
If you are using
ob_implicit_flush(true);
then you no need to call theflush();
but you have to use the ob_flush();.ob_flush(); brings out data from application initiated buffer. PHP internally has CGI buffer, ob_implicit_flush(true); will turn on the implicit flushing, which does not use CGI buffer and which uses application initiated buffer.
So once you are using ob_implicit_flush(true); then you have to use ob_flush();
I hope this helps.