Jump to content

[SOLVED] bandwidth calculator with time help needed


MiCR0

Recommended Posts

I am trying to work out the maths to build 2 functions download and upload any help would be great.

trying to work out how long it would take to download a file with there connection speed, as in time()+5000 until file would be finished.

Here is some of the speeds

 

function GetSpeed($Speed)
$SPEEDS[ 1] = array('DownSpeed' => 56000, 'UpSpeed' => 48000, 'NAME' => 'Modem 56k (V.92)'); 
$SPEEDS[ 2] = array('DownSpeed' => 64000, 'UpSpeed' => 64000, 'NAME' => 'ISDN 64k'); 
$SPEEDS[ 3] = array('DownSpeed' => 128000, 'UpSpeed' => 128000, 'NAME' => 'ISDN 128k'); 
$SPEEDS[ 4] = array('DownSpeed' => 1544000, 'UpSpeed' => 1544000, 'NAME' => 'T1');
return $SPEEDS[$Speed];

 

$speed = GetSpeed(1);

//$filedetails->size // files size in bytes

$speed['DownSpeed']/1024?? lost

 

Well....

 

If you have time (in seconds) = size/speed...

 

You just need to get size and speed in the same unit...  (both in bytes or both in KB... so on)

 

So, it looks like you have the values in kilobits...

 

Unless you're going to be using large numbers, you might as well just divide in bytes, since that's what filesize() will return...

 

For example:

 

//pretend $filesize is the size of a certain file
$dialup = GetSpeed(1);
$time = $filesize/($dialup['DownSpeed']/1024*;
echo "It would take {$time} seconds to download the file on dialup.";

 

Why the /1024*8?

 

Well, with kilobits...

 

A bit is 8 bytes, and kilo means 1024 (well.... in the world of computers for simplicity ;p)...

 

So, if you want it to kilobytes you have to do times 8.  Then, if you want it in bytes, you have to drop the kilobytes... In other words divide by 1024.

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.