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.

 

 

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.

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.