Jump to content

Bandwidth Control...


ChaoticResolve

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.