benjam Posted June 2, 2006 Share Posted June 2, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/ Share on other sites More sharing options...
poirot Posted June 2, 2006 Share Posted June 2, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/#findComment-41193 Share on other sites More sharing options...
benjam Posted June 2, 2006 Author Share Posted June 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/#findComment-41332 Share on other sites More sharing options...
poirot Posted June 3, 2006 Share Posted June 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/#findComment-41336 Share on other sites More sharing options...
benjam Posted June 6, 2006 Author Share Posted June 6, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/#findComment-42581 Share on other sites More sharing options...
nogray Posted June 6, 2006 Share Posted June 6, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/#findComment-42585 Share on other sites More sharing options...
benjam Posted June 29, 2006 Author Share Posted June 29, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11032-generating-dynamic-downloads/#findComment-50939 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.