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();

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.