1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can somebody explain flush() and ob_flush() in lamens terms?

Discussion in 'PHP' started by Christian Little, Oct 9, 2008.

  1. #1
    I've never used these commands before and somebody gave me a chunk of code them with. I read the doc on php.net, which says it flushes the output buffer - what the hell does that mean?

    There's no explanation about what 'flushing the output buffer' means or why I would want to do it.

    Thanks :)
     
    Christian Little, Oct 9, 2008 IP
  2. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Flush() sends all output to browser immediately, without waiting for the end of the script. Basically the use of this command is to update browser with new content. for Example:
    
    <?php
    echo "Loading...<BR>";
    flush(); sleep(2);
    echo "Loading Done...<BR>";
    flush(); sleep(2);
    echo "Done!";
    ?>
    
    PHP:
    ob_flush it requires ob_start command to be executed first before using this command.
    ob_start() begins making caches and prevents anything to show on browser until until ob_flush() is called.
    Example:
    
    <span>Start</span>
    <?php ob_flush(); ?>
    <span>END</span>
    <?php ob_flush(); ?>
    
    PHP:
    Thanks hope it helps
     
    mehdi, Oct 9, 2008 IP
    Christian Little likes this.
  3. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ohhh....cool :) I've always wondered about that gets done :)

    So if ob_flush requires you to ob_start first, what's the point of using this command? Is there any benefit to using it over the flush command?
     
    Christian Little, Oct 9, 2008 IP
  4. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you want to show your PHP page completely, not one after other content, then you may use ob_flush.
     
    mehdi, Oct 9, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    ob_start can also fix header already sent problems
     
    ads2help, Oct 9, 2008 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    I think that's more or less sweeping them under the rug, rather than actually fixing them. :)
     
    joebert, Oct 10, 2008 IP