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 warning : it's just an example from a full script which iam coding any answers ?
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
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 ?
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...
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.