Apache - Load page before script is complete

Discussion in 'Apache' started by DartPHP, Apr 13, 2008.

  1. #1
    Hey, I'm new at Apache and whatnot, so bear with me.

    I have my own web server, and when I run a script with a large loop like this:

    for ($i=0;$i<1000;$i++) {
      echo "text<br />";
    }
    PHP:
    It loads for about 30 seconds, then shows the page all of a sudden.

    e.g.

    (30 sec later)...
    Text
    Text
    Text
    Text
    Text
    Text

    But on a professional web host, it shows the result one by one as it loads.

    e.g
    Text
    (1 sec later)...
    Text
    (1 sec later)...
    Text

    Does this have something to do with my configurations?
     
    DartPHP, Apr 13, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    for ($i=0;$i<1000;$i++) {
      echo "text<br />";
      flush();
    }
    Code (markup):
     
    joebert, Apr 13, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Or put:

    
    ob_implicit_flush(true);
    
    PHP:
    at the top of the code.

    Jay
     
    jayshah, Apr 14, 2008 IP
  4. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can also put that configuration option in your php.ini file but having it in the code means that the script will perform the same even if you move it to a host without implicit flushing.
     
    Ladadadada, Apr 15, 2008 IP