Jump to content


Photo

Generating Dynamic Downloads


  • Please log in to reply
6 replies to this topic

#1 benjam

benjam
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationSalt Lake City, UT

Posted 02 June 2006 - 02:52 PM

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?
Windows 7
MySQL: 5.1.36-community
PHP: 5.3.2 VC9
Apache 2.2 (apachelounge VC9)

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 02 June 2006 - 03:01 PM

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]
~ D Kuang

#3 benjam

benjam
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationSalt Lake City, UT

Posted 02 June 2006 - 11:33 PM

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.
Windows 7
MySQL: 5.1.36-community
PHP: 5.3.2 VC9
Apache 2.2 (apachelounge VC9)

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 03 June 2006 - 12:33 AM

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.
~ D Kuang

#5 benjam

benjam
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationSalt Lake City, UT

Posted 06 June 2006 - 08:53 PM

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?
Windows 7
MySQL: 5.1.36-community
PHP: 5.3.2 VC9
Apache 2.2 (apachelounge VC9)

#6 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 06 June 2006 - 09:07 PM

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.

NoGray.com


#7 benjam

benjam
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationSalt Lake City, UT

Posted 29 June 2006 - 06:18 PM

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.
Windows 7
MySQL: 5.1.36-community
PHP: 5.3.2 VC9
Apache 2.2 (apachelounge VC9)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users