Linux – PHP Output buffer flush issue on Apache/Linux

apache-2.2linuxPHP

I'm running into issues with the PHP output buffer flushing on my Linux web server. The output buffer is maintained correctly and all the right data is pushed to it in my code, but the usual flushing mechanisms won't flush it to the browser. I have tried everything posted here: http://php.net/manual/en/function.flush.php but no success so far.

I got a small script from php.net to test it:

<?php
    ob_start();
    for($i=0;$i<70;$i++)
    {
        echo 'printing...<br />';
        ob_get_flush();
        flush();
        usleep(300000);
    }
?>

This should print "printing…" to the browser 70 times, one line every three seconds. This works fine on my other testing environment which is based on Windows (still using apache, XAMPP package), but on my Linux server it doesn't. It waits for the script to finish before giving anything to the browser, basically ignoring the whole flush command.

If anyone has experienced this before or knows of anything that could help (be it server configuration or adjustment to code) it would be greatly appreciated!

Best Answer

I had this problem and found that the lines:

while ( @ob_end_flush() ); // even if there is no nested output buffer
flush();

would solve the problem.

Results may vary. This works on my system with IE and Apache 2.0.55.

Jeff

Related Topic