PDA

View Full Version : download script times out



rogerke
03-20-2009, 08:36 AM
so, my friends have a band and asked me if i could write one of those scripts with download codes. i agreed and i'm pretty much there, except for the problem that the downloads often time out it seems.

the big issue is that every code can only be used once and the real location of the file should never be known. therefore, i can not use 302 redirecting to the file because that would give them a direct link to the file. so i'm forced to read the file in php and then output it right away, all that works fine, except that it stops if it takes too long it seems.

i set the execution time of php to 9999, but some searches told me that there is a limit of 40 secs cpu time on bluehost?

either way, any workarounds or solutions appreciated.

wysiwyg
03-20-2009, 11:36 AM
Execution time is not the same as CPU time. Ideally, your script is only processing a fraction of the time it spends executing.

A download script like you're describing probably reads a portion of the file, outputs it to the page, and flushes it from memory, until it has gone through the whole file.

The only processing your script is actually doing is reading the file, the rest of the time it's basically sleeping.

Might I ask why it matters if visitors know the direct link to the file?

rogerke
03-20-2009, 02:31 PM
of course you might :): because they have to pay to get the album.

in short:

they paypal my friends who play in the band that made the album 10$

my script generates a one time only link (like download.php?code=412n34uqfh0821h4rbg0s)

if the code is in the database, the file is sent to the browser and the code is removed from the database

we don't want people to get the real file location so they can link it on fora and stuff :)

you're right about the script by the way: it reads through the file, flushes, etc. i replaced it by readfile(), thinking that would have been more efficient and less cpu consuming, but no luck there.

i knew there was a difference between script runtime and cpu time. i'm guessing i'm well within the 9999 seconds script time, so i must be reaching the cpu time limit.
my first idea was to use some forking, creating a new thread, a new process, that would again get 40 seconds. but pcntl is not supported either on bluehost. it's starting to look impossible

bhobbs
06-24-2009, 11:25 PM
Did you guys figure this out? Is it possible. Because I am doing the same thing.

My script uses readfile(). It was someone else's script that I adapted. It works really well, but times out when people have slow connections.

What can I do?

KazanDaemon
06-29-2009, 04:48 PM
You need dedicated IP to run this script. Without dedicated IP your script will be terminated after 5 minutes.