Page 1 of 6 123 ... LastLast
Results 1 to 10 of 56

Thread: Flushing output buffer

  1. #1
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Flushing output buffer

    I've just moved to Red Fox and my PHP scripts that flushed the output buffer to the browser on my old host now don't flush the output buffer until the whole script has finished processing.

    I've set the following:

    ini_set('output_buffering', 'On');

    and I use these commands to flush the output buffer:

    ob_flush();
    flush();

    Does anyone have any idea how I can get the output buffer to flush its contents to the browser before the script has finished all of its processing?

  2. #2
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    I'm not entirely sure whether you can set output buffering with ini_set? That could possibly be a reason. To test you could just start the buffer with
    PHP Code:
    ob_start(); 
    before anything is output in your script.
    I have flushed many a buffer with no problems on scripts run on redfox. The only problems I have ever come across involve using output buffer compression as there is an irritating known php bug on Windows.

  3. #3
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi, thanks for replying.

    When I first ran one of my scripts that flushes the output buffer it produced an error with a link to this page of the PHP manual:

    http://uk.php.net/outcontrol

    That page prompted me to try

    Code:
    ini_set('output_buffering', 'On');
    On my old host it was fine without using that line.

    Does the following code flush the buffer every 2 seconds for you or does it wait until the whole script has finished processing:

    Code:
    <?php
    
    if (ob_get_level() == 0) ob_start();
    
    for ($i = 0; $i<10; $i++){
    
            echo "<br> Line to show.";
            echo str_pad('',4096)."\n";    
    
            ob_flush();
            flush();
            sleep(2);
    }
    
    echo "Done.";
    
    ob_end_flush();
    
    ?>
    I've just taken that from the PHP manual page for flush():

    http://uk.php.net/manual/en/function.flush.php

    For me it waits 20 seconds then outputs everything at once.

  4. #4
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    Okay, yes I do get the same behaviour on RF, whereas locally (Apache 1.3, PHP5, OS X) the script is working correctly. Even more strangely, if we take output buffers out of the equation and run this script:
    PHP Code:
    for ($i 0$i<10$i++){
            echo 
    "<br> Lines to show.";
            echo 
    str_pad('',4096)."\n";    
            
    sleep(2);
    }
    echo 
    "Done."
    we get the same behaviour where everything is sent to the browser at the very end of execution rather than as things are echoed.

    More investigation is certainly needed, but I wonder if Warren has any ideas?

  5. #5
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    I wonder if this has to do with the fact we run PHP in CGI mode as opposed to unstable ISAPI?

    Maybe with CGI, it returns the data to IIS in one go as opposed to bit by bit?
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  6. #6
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    Quote Originally Posted by Warren Ashcroft
    I wonder if this has to do with the fact we run PHP in CGI mode as opposed to unstable ISAPI?

    Maybe with CGI, it returns the data to IIS in one go as opposed to bit by bit?
    I found a bug that sounds like our problem, but it appears to have been fixed in the latest builds http://bugs.php.net/bug.php?id=34429.

  7. #7
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Quote Originally Posted by nick
    I found a bug that sounds like our problem, but it appears to have been fixed in the latest builds http://bugs.php.net/bug.php?id=34429.
    Thats definatly the bug here, but they say its been fixed on 18.12.05, we use 5.1.4 which was released on 04.05.06?
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  8. #8
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    Quote Originally Posted by Warren Ashcroft
    Thats definatly the bug here, but they say its been fixed on 18.12.05, we use 5.1.4 which was released on 04.05.06?
    Looking on Carbon it appears to be running 5.1.2

  9. #9
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Quote Originally Posted by nick
    Looking on Carbon it appears to be running 5.1.2
    Thats odd, my work log shows a PHP update to 5.1.4 a couple of weeks ago...

    Anyway, I will get PHP updated tonight across all the web servers, hopefully it should resolve the buffer bug.
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  10. #10
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That would be great, thanks very much.

    One thing I noticed though is this:

    http://uk.php.net/manual/en/function.flush.php

    "Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.

    Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client."

    I know very little about servers, so I may be barking up the wrong tree here, but could what it says above affect the behaviour anyway even if you update PHP tonight?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •