1

I have an app where people download relatively large CSV files. Sometimes it can take a minute or more.

At 1 minute, I want to show a message about the long download time in the browser. How can I watch the download time / length that the request is open in PHP or JS?

Don P
  • 60,113
  • 114
  • 300
  • 432
  • http://stackoverflow.com/a/1598793/1066828 check this... might help you... – Fahim Parkar Aug 30 '13 at 17:45
  • I'd do this with jQuery personally. Use a timer and figure out a way to determine if the download is complete or not. – James P. Aug 30 '13 at 18:07
  • James if you're just setting a timer, how would jQuery help? – Don P Aug 30 '13 at 18:20
  • @DonnyP: Well, it would make it easier to add another action to the download link, if that's how the download is being triggered. – user1618143 Aug 30 '13 at 18:31
  • With newer browsers it can be done. I know that MEGA has such a feature. I only could find that question about this: [How exactly does MEGA's download work?](http://webapps.stackexchange.com/q/41068). As far as i know MEGA first downloads the file to a local storage (with progress bar) and then triggers the normal download which then is just a transfer from the local storage to the download destination, but looks like a normal download - only faster ;) – t.niese Aug 30 '13 at 21:07

1 Answers1

0

First of all, I don't think there's a useful way to do this in straight PHP. PHP is a server-side language, and this is a client-side problem.

The solution that springs to mind is to set up a javascript setTimeout when the download link is clicked. Then watch to see when the download finishes - this question has a clever cookie-based method - and clear the timeout when it finishes.

Community
  • 1
  • 1
user1618143
  • 1,728
  • 1
  • 13
  • 27
  • That cookie-based solution is interesting, but I wonder if it works in this case. The other question seemed to care about when a file had finished generating, i.e. when the download started, while this cares about when the download finished. Browsers receive cookies before the download starts, so if they set the cookies as soon as they receive them (I don't know if they do), then this might not work. – Jeremy Aug 30 '13 at 20:57