sleep functions and iframes ?

Discussion in 'PHP' started by zAxxx, Jun 21, 2009.

  1. #1
    Hello all.
    I've a problem with Sleep function and iframes
    Here are the codes
    
    // A.PHP File
    <?php
    for($i=1;$i<=3;$i++){
    echo "<iframe width='40%' src='b.php'></iframe>";
    sleep(2);
    }
    ?>
    
    Code (markup):
    
    <?php
    echo "Hello World ! ";
    echo date('h:i:s') . "\n";
    ?>
    
    Code (markup):
    When I browse a.php i get the same date from b.php codes :confused:

    warning : it's just an example from a full script which iam coding

    any answers ?
     
    zAxxx, Jun 21, 2009 IP
  2. Sudoku-Master

    Sudoku-Master Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you have to use flush() to send the buffer to the browser befor you use sleep()...

    without flush the server buffered the code and send it complete to the browser, so all iframe load at the same time -> same date
     
    Sudoku-Master, Jun 21, 2009 IP
  3. zAxxx

    zAxxx Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey Sudoku-Master
    I don't know a lot about flush function
    and I have tried that but it didn't work successfully ..
    I have edited the a.php
    this is the unsuccessfully code :
    
    <?php
    // a.php file
    for($i=1;$i<=3;$i++){
    echo "<iframe width='40%' src='b.php'></iframe>";
    flush();
    sleep(2);
    }
    ?>
    
    Code (markup):
    but it didn't work


    what now ?
     
    zAxxx, Jun 21, 2009 IP
  4. Sudoku-Master

    Sudoku-Master Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    maybe you have to use ob_flush() too... read the comments to this function too, maybe you can find there a solution... and try different browsers...
     
    Sudoku-Master, Jun 21, 2009 IP
  5. zAxxx

    zAxxx Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I Can't for now


    any suggestions please ?
     
    zAxxx, Jun 22, 2009 IP
  6. franklyn

    franklyn Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You have to understand that the code in b.php is only run when the final page of A.php is served which means that it creates all the iframes and then the browser loads the result from b.php which is why they all have the same timestamp.
     
    franklyn, Jun 22, 2009 IP