Jump to content

Archived

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

benjam

Generating Dynamic Downloads

Recommended Posts

I have a script that is generating a rather complex download and it takes a long time to generate this download, and I was wondering if there is a way to begin the download before the generation is complete and have it send the data directly to the user.

I have seen this done with phpMyAdmin, where when you export a database, the download begins immediately and as the script generates the download, it sends it to the user.

How might I do this?

Share this post


Link to post
Share on other sites
It depends on how the download is "generated"; if the script takes a long time doing this, the download will start later.

If you're simply using this to let ppl download files without them knowing where they really are, you can use:
[a href=\"http://www.php.net/readfile\" target=\"_blank\"]http://www.php.net/readfile[/a]

Share this post


Link to post
Share on other sites
I mean, the script runs, and dynamically creates the file that is being downloaded. The script consists of a loop that runs once for every day in a year (so 365 times) and runs 5-6 queries in each loop. Therefore, it takes a rather long time to generate the data.

I would like it to work by immediately starting the download and just outputting the data directly to the user as the script runs, instead of running the whole script and send ing the finished product when it is completed.

Share this post


Link to post
Share on other sites
Wow, that's pretty resource-hogging.

I don't know if it's possible to do what you want, but I guess chaching it would be a good idea too.

Share this post


Link to post
Share on other sites
I don't want it cached, I would like to have it dynamically downloaded.
Sent to the user AS it's being generated.

Anybody besides poirot have any suggestions?

Share this post


Link to post
Share on other sites
I agree with poirot that the script is a resource hog and if there are a lot of people running at the same time, it may crash your server.

But you always can flush the output by using [a href=\"http://us2.php.net/manual/en/function.flush.php\" target=\"_blank\"]flush()[/a] This way the user will start seeing data before the script is done processing.

Share this post


Link to post
Share on other sites
I tried that, and it still seems to wait a long time before the download even starts.

I also tried it with the ouput, instead of being downloaded, was directed at the browser (echo) and it waited until there were at least 50 or so lines before outputting anything. It was set up to flush each line as it came to it.

Oh well, I guess it works good enough the way it is.

But for future reference, it doesnt really matter if my server can or can't handle the load, my question was how could I do something. This question was prompted by my current situation, but it can also be applied in other scripts.

I appreciate the concern, but that concern is mine. I know how many people are going to be using the script at a time, and I know what my server can handle.

Thanks for your help.

Share this post


Link to post
Share on other sites

×

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.