Jump to content

Getting Output While PHP Script Processing


zero1

Recommended Posts

Hi all,

 

I can't get the specific answer on my search query in this forum so I've decided to post one. So pardon me for being n00bish, here goes my question.

 

Let's say I have this code...

<?
echo "Downloading file......";
file_get_contents("BigFile.Dat");
echo "done!";
?>

In my test, echo only shows after the script have finished downloading the file.

How can I make the webpage show before download ...

Downloading file......

...and display next after download...

Downloading file......done!

 

I'll be needing this to inform the user that the script is still processing just as to not let them think that the browser hanged.

 

 

Link to comment
Share on other sites

Hmmm.. AJAX. I can accomplish the same task with iframe but I need a pure PHP code.

 

How bout this , what if I open a socket to the client that accesses the PHP page then send a HTTP reply.

Would it be possible? or how about using "headers"?

Sort of like...

<?
$fp = fsockopen ($host, 80);
fwrite($fp,"HTTP/1.1 200 OK\r\nContent-Type: text/hml\r\n\r\nDownloading file......");
file_get_contents("BigFile.Dat");
fwrite($fp,"HTTP/1.1 200 OK\r\nContent-Type: text/hml\r\n\r\ndone!");
?>

Haven't anyone accomplished this? Is it possible to get the handle of the current socket transaction, which is the first instance the user accesses your script?

 

Thanks for the reply.

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.