Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    output of php script wont display in browser until the script has finished executing

    im testing the following script and it wont send 1 2 3 until the script has finished executing.

    What can i do to flush the buffer after every echo statement??

    PHP Code:
    <?php 

    echo "1";
    ob_flush();flush();
    sleep(5);
    echo 
    "2";
    ob_flush();flush();
    sleep(5);
    echo 
    "3";
    ob_flush();flush();

    ?>

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    I think you need to use ob_start() before any of that will work...
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    ob_start turns on output buffering. ob_flush() will not work without it.

    Unfortunately what you're trying to do even with flush will not work. This is because of the way sockets work internally to any operating system. Most sockets will read in 4Kb chunks so your output will not be even passed through to your ISP until it fills up its buffer. Even then your ISP will also perform the same action.

    The only way content less than the buffer gets to you is when the output is finished - IE the system realises that there is no more and passes it on down the line. Not that you'll even notice this without any sleep() commands..
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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