ChaoticResolve Posted February 27, 2007 Share Posted February 27, 2007 Hi, I'm trying to make a script which manages downloads, at the moment i've got a script which pritty much does the following... header("HTTP/1.1 200 OK"); header("Content-Length: $filesize"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=$filename"); header("Content-Transfer-Encoding: binary"); if(file_exists($filepath) && $fh = fopen($filepath, "rb")){ while($buf = fread($fh, $buffer)) { echo $buf; bw_log(); } fclose($fh); } else { header("HTTP/1.1 404 Not Found"); } It's a little more complex but basically the bw_log function adds the $buffer size to the total bandwidth and stops the script for a second with sleep(1) before continuing fread(). Thus limiting bandwidth to $buffer byte per second. This works but with users who's internet speed is less than the $buffer size my bandwidth record is over estimating. Any Ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/40358-bandwidth-control/ Share on other sites More sharing options...
magnetica Posted February 27, 2007 Share Posted February 27, 2007 Work out how much it is over estimating by (is this doesn't vary) And minus this from the estimaiton Link to comment https://forums.phpfreaks.com/topic/40358-bandwidth-control/#findComment-195277 Share on other sites More sharing options...
ChaoticResolve Posted February 27, 2007 Author Share Posted February 27, 2007 That wouldn't work because if the limit is 100kbps Some users will only have a connection up to 50kbps and others may have the full 100kbps, so if i subtract 50kbps to account for the slow 50kbps connection it wont be accurate for any speed above that. Link to comment https://forums.phpfreaks.com/topic/40358-bandwidth-control/#findComment-195278 Share on other sites More sharing options...
ChaoticResolve Posted February 28, 2007 Author Share Posted February 28, 2007 *bump* Any ideas? ??? Link to comment https://forums.phpfreaks.com/topic/40358-bandwidth-control/#findComment-196290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.