Jump to content

Generating Dynamic Downloads


benjam

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?
Link to comment
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]
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

  • 4 weeks later...
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.
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.