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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.