
|
View Full Version : Bandwidth tracking / throttling
kkropp 09-27-2006, 06:27 PM Does anyone know of a PHP script that can be used to track bandwidth usage on a per logged in user basis when downloading files from a site?
Also, is there a way to throttle bandwidth (to say 100k/sec) with PHP for a regular old download?
Thanks!
hubhub 10-07-2006, 07:49 AM Search for mod_bandwidth or mod_throttle...for apache 1.3 I'm afraid.
For tracking I recommend you a stats script like awstats or webanalyzer
Does anyone know of a PHP script that can be used to track bandwidth usage on a per logged in user basis when downloading files from a site?
Also, is there a way to throttle bandwidth (to say 100k/sec) with PHP for a regular old download?
Thanks!I have a script like this which I made back a while ago on CD. The only thing is that your server will need a little bit of memory for it as it parses the file through the PHP script, and simply 'limits' the amount of bytes output each second. This can also be good to hide the original file source.
Regards,
Drac
kkropp 10-10-2006, 10:00 AM I have a script like this which I made back a while ago on CD. The only thing is that your server will need a little bit of memory for it as it parses the file through the PHP script, and simply 'limits' the amount of bytes output each second. This can also be good to hide the original file source.
Regards,
Drac
Hi Drac,
Thanks for the input. We ended up just creating a script which reads in x number of bytes, then sleeps for the duration left in a second that it needs to to make it xk/sec and then just does that continously. Seems to work.
We ended up just creating a script which reads in x number of bytes, then sleeps for the duration left in a second that it needs to to make it xk/sec and then just does that continously. Seems to work.Sounds a little confusing, but if it works, then that's great. If you run into any trouble with it in the long run, you can always send me a message and I can look for the script I put together in the days when I used to do alot of PHP scripting.
Regards,
Drac
kkropp 10-10-2006, 10:58 AM Sounds a little confusing, but if it works, then that's great. If you run into any trouble with it in the long run, you can always send me a message and I can look for the script I put together in the days when I used to do alot of PHP scripting.
Regards,
Drac
I'm all for looking at another way to do it. If you can find yours I'd love to take a look.
No problems. I'll take a look during the day (12:43AM right now), and post it here :)
Regards,
Drac
Here is the script as requested. Let me know if it works because I haven't tested it since the last edit I don't think.
<?php
$file = "dir/file.exe"; // file to be send to the client
$newfilename = "newfilename.exe"; //you can hide the original filename
$speed = 100; // 100kb/s download rate limit
if(file_exists($file) && is_file($file)) {
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: filename=$newfilename");
$fd = fopen($file, "r");
while(!feof($fd) and (connection_status()==0)) {
echo fread($fd, round($speed*1024));
set_time_limit(0);
flush();
sleep(1);
}
fclose ($fd);
}
?>
kkropp 10-12-2006, 09:59 AM Looks almost identical to what we are doing. :)
Thanks for posting that!
MartynD 10-27-2006, 08:29 PM How does this work, would i just upload that script to my site?? or?? explain please - i've always wondered how to throttle/limit the bandwidth used.
How does this work, would i just upload that script to my site?? or?? explain please - i've always wondered how to throttle/limit the bandwidth used.You add that script into a PHP file. Then you have to add your file (including directory) into the $file variable. The $newfilename variable can be the same as the $file or you can change it so you can completely hide the original file name.
This was taken from a download system of mine so that it can even support downloads which require payment - so that it would hide the original download and allow them only to download what they have bought.
You could also change the $file variable to read another variable such as $get so your script can be dynamic - for instance, you can change the file simply by the URL:
- http://www.yourdomain.com/download.php?get=filename.exe
Just have to play around with it.
Regards,
Drac
MartynD 10-27-2006, 08:45 PM Hmm sounds nice, I wouldn’t mind some kind of installation file, maybe develop this file further?
Hmm sounds nice, I wouldn’t mind some kind of installation file, maybe develop this file further?This is only a snippet of code - it does not include an installation file.
It was posted to assist the thread starter and anyone in the same situation, to capping a file parsing through PHP.
Regards,
Drac
|