Jump to content

problem sending output to a browser while php script is running


kevinkhan

Recommended Posts

im testing the following script and it wont send 1 2 3 until the script has finished executing.

 

What can i do to flush the buffer after every echo statement??

 

<?php 

echo "1";
ob_flush();flush();
sleep(5);
echo "2";
ob_flush();flush();
sleep(5);
echo "3";
ob_flush();flush();

?>

The server runs the script, then sends the output to your browser.  It waits until the script has finished before sending the output, so that would not work.

 

If you run it through the terminal "php script.php", you would then be able to see it how you've asked, but not through a browser.  Also, if it's a remote server, you would have to use SSH to run it from there, not the URL to a script.

You'll need to this with Javascript or if you're feeling brave AJAX - I'd stick with Javascript to begin with tho!

even if your not brave, or got blue paint on your face. Ajax is the way to go.

HAve a look in to jquery ajax. Quite some tutorials out there and within an hour you should be able to do some simple stuff with it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.