pycoder
11-03-2002, 04:08 AM
Is there a way to create a download buffer in php? Say I get alot of visitors to my file website. And now I need a buffer so noone complains about slow downloads.
Ok here it goes:
I would like to make a script where 10people can download 1 file at the same time. But once the 11th+ person comes it puts them in line and gives them a time till download. Lets say it gives them 5minutes. It then counts down and once it hits 0, the download starts.
Example: http://www.fileplanet.com - This is where I got the idea.
Thank you very much in advance.
sasha
11-03-2002, 11:17 AM
php/mysql solution
You could have a counter that increases every time someone starts download and decreases after specified period of time (time needed for file download) . If you ask your users about their connection you can get more specific about this time.
Every time download starts and counter increases, entry for estimated time is added in the table, together with session id. This is for preventing the same person from starting more then n downloads.
When new visitor tries download and counter is at 10 they see the page that tells them the shortest estimated time from the above table and has META REFRESH set to that time or META REFRESH set to some fixed interval , like 10 sec, that keeps them updated about this estimated time before their download starts.
You could track these requests as well, so you can send the file to the first person in the queue once when the download slot opens.
This is really rough outline and you will probably run into more problems if you try implementing it.
I believe FilePlanet/GameSpy have written their own server side software (ISAPI plugin last time I heard) to provide the functionality your talking about. To provide a better platform for load balancing.
Correction... they have written their own web server software now.
MarlboroMan
11-05-2002, 07:41 AM
Written their own webserver? Strange, netcraft.com still reports Fileplanet.com as running on IIS 5.0
You don't actually download a file off the hostname "www.fileplanet.com" ;)
Do a bit of proper digging into what lies behind FilePlanet....
UH-Matt
11-05-2002, 08:14 AM
expanding on sasha's idea.
Have some PHP which increases a counter by say x minutes everytime someone hits the download url...
Then for the download url an IF statement.
So if the counter is so high, it tells the user to wait...
If the counter is under a certain figure the download starts..
Just a few ideas, as i think about it more.. it gets more and more complex..