Buffer flush doesn't work quite as expected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Cartwright

    Buffer flush doesn't work quite as expected

    Hi,

    I've got a PHP script (running on MacOS X, PHP 4.1.12) which uploads
    bookings from one database to another, and I'd like to have the screen show
    progress as it happens (each time I process a booking, I write a line
    summarising it to the browser with 'print')

    From RTFMing and Googling, it seems that I should be able to do this by
    turning output buffering on and using ob_flush() et al. However, this only
    sort-of works, in that instead of getting output line by line, I get a
    multi-line chunk on the browser from time to time.

    Am I stuck with having this chunk-by-chunk visualisation, or can anyone
    please suggest a way that I can make it force each line to the browser as I
    write it?

    Thanks in anticipation,

    David C


  • Sergej Andrejev

    #2
    Re: Buffer flush doesn't work quite as expected

    Here is an example which works for me, but I personaly recommend not to
    use buffering at all
    <?
    function sample($buffer) {
    global $i;
    if(!isset($i)) $i = 1;
    $bufer = "$i<br />";
    $i++;
    return ($bufer);
    }

    // don't forget to start buffering
    ob_start("sampl e");

    ob_flush();
    ob_flush();
    ob_flush();
    ob_flush();

    // and don't forget to end it
    ob_end_flush();
    ?>

    Comment

    • Jasen Betts

      #3
      Re: Buffer flush doesn't work quite as expected

      In article <dcqahm$br1$1@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, David Cartwright wrote:
      [color=blue]
      > From RTFMing and Googling, it seems that I should be able to do this by
      > turning output buffering on and using ob_flush() et al. However, this only
      > sort-of works, in that instead of getting output line by line, I get a
      > multi-line chunk on the browser from time to time.[/color]

      the result you see may depend on your browser, web server etc...
      I did something similar in perl and got character by character output in
      mozilla but not in IE.

      Bye.
      Jasen

      Comment

      Working...