PDA

View Full Version : Progress Bar for Large File Download



SiriusB
11-15-2007, 06:26 PM
Hi there

I have been developing a script to collect Folding@Home stats for my team and present them in a weekly news post. The script works just fine using a local copy of the official F@H stats file.

However, for the script to function properly I need to access/download the stats file from the F@H website at least once a week. Unfortunately this stats file is pretty damn big - about 18mb if I recall.

At the moment I have used the file() function in PHP to stick the file into an array. The problem with this is the script sits there for some time while it downloads the data.

I don't mind the download time as such, it is the complete lack of information given to the user. Is it possible to create a progress bar for the download, so at least we know what is happening?

If that is not possible, is there a way to parse a file line by line when it is not held locally? Due to its size [840,000 lines] it takes up a lot of memory and doing it a line at a time would keep memory usage down.

The file in question is here: http://fah-web.stanford.edu/daily_user_summary.txt

r2b2
11-15-2007, 06:33 PM
Have you thought about dragging the file across using wget or something similar and then processing the file using cron and outputting the results to an html / php file that users can then look at?

(i.e. process it in the background)

SiriusB
11-15-2007, 07:29 PM
That didn't occur to me. Goodness knows why not!

Since my PHP code works, is it possible for a cronjob to run a small PHP script periodically?

Since the parsed data goes into a database, I could also create a file with a flag that my main page checks before loading. To stop the user from performing actions during the update.

Are cronjob easy to set up on Hostmonster? I have never tried :p

r2b2
11-15-2007, 07:35 PM
Basically on HostMonster I think you just use wget to call your site (e.g. wget http://mysite.com/dostuff.php) However I haven't used it personally so hopefully someone who has will comment further.

For cronjobs calling PHP, see here (http://helpdesk.hostmonster.com/kb/index.php?x=&mod_id=2&id=190)

SiriusB
11-15-2007, 07:51 PM
Ahh nice one. That link is just the thing.

Thanks for your help :)