Hello, I am trying to write a PHP script that executes gradually as seperated by a time pause between its different parts. Here's a working example: <?php set_time_limit( 0 ); //unset the execution time defaut limit (30 sec.) //Do...(php code) echo "Done part 1<br>\n"; sleep(10); //pause for 10 sec. //Do...(php code) echo "Done part 2<br>\n"; sleep(10); //pause for 10 sec. //Do...(php code) echo "Done part 3<br>\n"; . . . . . . ?> PHP: The code above does the following: execute>>pause for 10 sec.>>resume execution>>pause for 10 sec.>>resume......>>OUTPUT AFTER THE END OF THE SCRIPT IS REACHED But I want it to do the following: execute>>OUTPUT>>pause for 10 sec.>>resume execution>>OUTPUT>>pause for 10 sec.>>resume execution>>OUTPUT...... I do know why PHP was called so and I do know what that means, but is there anyway to make the script pause for a while, output all the code executed before it paused and before the script ends (while it is processing the script), then continue this way until the end of the script...
It may be that with so little output actually being written, apache and/or tcp/ip will wait to fill a packet before sending your data. So effectively it comes all at once. It would be more reliable to simulate delays with Javascript: <html> <head> <script language="Javascript" type="text/javascript"> function reveal() { setTimeout("document.getElementById('part2').style.display = '';", 3000); setTimeout("document.getElementById('part3').style.display = '';", 6000); } </script> </head> <body onload="reveal();"> <span id="part1"> Done part 1<br></span> <span id="part2" style="display: none;"> Done part 2<br></span> <span id="part3" style="display: none;"> Done part 3<br></span> </body> </html> HTML:
That's a useful tip, but I want to execute other PHP codes in the different parts (not only echo's) and the output of each part would be much more than just "Done part #".
If you generate enough output during each phase of the program it will probably just work This happens naturally whenever you write a script that has delays on the backend.