View Full Version : Download cue (ticket)
mucho
September 22nd, 2005, 10:58 AM
Hi everybody,
right now I`m working on a site that deals with great amounts of downloadable files - some of the ma very large. In order to maintain a consistent level of bandwidth I`m trying to prevent that more than one of these files is being downloaded at the same time.... sort of like a download cue or a ticketing system.
There are other models, for example that only one large file may be downloaded within one hour...etc.etc.
Do you guys have an idea of how I can solve this problem effectively?
Thanks in advance,
m.
bwh2
September 22nd, 2005, 02:03 PM
In order to maintain a consistent level of bandwidth I`m trying to prevent that more than one of these files is being downloaded at the same time.... sort of like a download cue or a ticketing system.
There are other models, for example that only one large file may be downloaded within one hour...etc.etc.
are you talking per user or all users?
mucho
September 22nd, 2005, 02:30 PM
per user. Each user must be logged in in order to download files. (It`s CI-Net and files a logos - just in case you`re wondering). Perhaps the files (large ones) can be somehow flagged in the db, so each time an access to one of the flagged files is taking place all other flagged files are locked.... makes sense.
thx,
m.
bwh2
September 22nd, 2005, 03:41 PM
Perhaps the files (large ones) can be somehow flagged in the db, so each time an access to one of the flagged files is taking place all other flagged files are locked.... makes sense.
you got it... sort of. basically you have a db for your users (obviously you need this for a login system). each time the user downloads a large file, their user acct gets marked with a timestamp. then you just reference the timestamp when the user next attempts to download a large file (large files are marked in the files table). if the time is less than your minimum, the links are inactive (or however you want to do this, they get redirected, whatever).
mucho
September 22nd, 2005, 05:36 PM
@bwh2: thanks for the feedback. I suppose you have picked up on the time out version. I thought of that a little more too... one big DL per hour. However, let`s say there is a user that has narrow band access and A) uses longer than an hour (unlikely, but possible. We`re dealing with 57MB max) and B) when he uses less than an hour. All other users will be blocked for the remianing time (one hour - x). B) is prolly the way to go, but I can`t stop thinking about an idea how this could be solved more effectively. I still see this: e.g. user 55 is DLing, user 87 is trying to DL but is blocked until user 55 has completed his DL.
Then again a bandwidth monitor script would be the coolest. Once the bandwidth is lower than the minimum operating requirment, all heavy files are blocked and will only reopen once the bandwidth is above the minimum....ahhhh I`m just thinking loud here. Theories.....
thanks again,
m.
mlk
September 23rd, 2005, 03:27 PM
If a dial up user d/ls your file he's probably not going to use that much bandwidth anyway (it'll be spread over a longer time, but the download rate will be ), so I'd go with queuing users using an approximate d/l time (like 10 min for 20 megs)
mucho
September 26th, 2005, 02:50 AM
I`m doing the "rain barrel" version. big files are flagged and each time a big file is dld, the meter gets cranked up a notch. When it`s full, the files a blocked for time x.
thanks for all you`re feedback.
m.
ironikart
September 26th, 2005, 11:04 PM
You could probably get a little more efficient at handling this. I'd go with a separate table for queuing downloads and add and remove rows from that table (maybe plug that into some custom session handling).
Just remember to optimise or vaccum your database periodically and your database will thank you.
mucho
September 27th, 2005, 02:47 AM
ironikart,
can you eloborate on that.... I`m not sure what you have in mind.
thanks,
m.
teiz77
September 28th, 2005, 06:15 AM
here's an example that should work for php
<?php
$name = getcwd()."/file.ext";
$fd = fopen($name, 'rb');
if($fd == false) {
die("<font color=red>ERROR: File not found.</font>");
}
if($fd) {
/*
insert the code to flag a file in the db being dowloaded here.
*/
// send the right headers
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Content-type: application/octet-stream");
//header("Content-Disposition: attachment; filename=\"test.exe\"");
header("Content-Disposition: inline; filename=\"test.exe\"");
header("Content-Transfer-Encoding: binary\n");
header("Content-length:".(string)(filesize($name)));
sleep(1);
while(!feof($fd)) {
$buffer = fread($fd, 2048);
print $buffer;
$bytesSent+=strlen($buffer);
}
fclose ($fd);
if($bytesSent==filesize($name)) {
/*
insert the code to deflag a file in the db being dowloaded here. If I were you I'd also set a time limit for downloading files. This is only to prevent people from downloading 2 files at the time. If a download fails, and the deflag command is not executed the user cannot download files anymore... that's why you should also a timelimit so that after a set amount of time the user can download again.
*/
}
}
?>
mucho
September 28th, 2005, 06:39 AM
teiz77, COOL! Let me try that...
thanks,
m.
teiz77, this looks pretty much like usual binary/upload script? Am I missing something here???
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.