Update page while PHP script executes

If you have a script that runs for a long time and you would like to
update the browser with some progress reports here is a very simple way
of doing it:


<div id="messages"></div>
function w($message){
?> <script language="javascript">
document.getElementById('messages').innerHTML =
document.getElementById('messages').innerHTML + "<?=$message;?>";
</script> <?php
@ob_flush(); @flush();
w("Here is a message");
w("And another message");
w("And yet another message");


View an example here: click

Leave a Reply

Your email address will not be published.