Web Analytics Made Easy -
StatCounter output of php script wont display in browser until the script has finished executing - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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

    Comment


    • #3
      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..
      "Tango says double quotes with a single ( ' ) quote in the middle"
      '$Name says single quotes with a double ( " ) quote in the middle'
      "Tango says double quotes ( \" ) must escape a double quote"
      '$Name single quotes ( \' ) must escape a single quote'

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎