Help needed with calculation

Help needed with calculation

am 15.11.2009 22:39:49 von chris_payne

Hi everyone,

I'm not sure of the correct formula for this, if I have a file - just
for example, that is 10245458756 bytes long and the download speed is
60KB a second, what formula would I use to calculate how many
seconds/minutes/hours it would take to download the file?

Maths really isn't my strong point and formulas go over my head
otherwise I wouldn't ask :-(

Thanks everyone

Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Help needed with calculation

am 15.11.2009 22:46:26 von Ben

Chris Payne wrote:
> Hi everyone,
>
> I'm not sure of the correct formula for this, if I have a file - just
> for example, that is 10245458756 bytes long and the download speed is
> 60KB a second, what formula would I use to calculate how many
> seconds/minutes/hours it would take to download the file?
>
> Maths really isn't my strong point and formulas go over my head
> otherwise I wouldn't ask :-(
>
> Thanks everyone
>
> Chris

$size = 1024548756; // in bytes
$kb_per_sec = 60; // I assume you'll fill these in from elsewhere?

$b_per_sec = $kb_per_sec * 1024;

$seconds = $size / $b_per_sec;
$minutes = 0;
$hours = 0;

if($seconds > 60)
{
// 60 seconds to a minute
$minutes = (int)($seconds / 60);
$seconds -= $minutes * 60;

if($minutes > 60)
{
// 60 minutes to an hour
$hours = (int)($minutes / 60);
$minutes -= $hours * 60;

// if you want to go further and calculate days, have at :)
}
}

You could also approach this using modulus, but if you're not confident
with math, this might be a more intuitive approach.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Help needed with calculation

am 15.11.2009 22:48:44 von Adam Shannon

If the download speed is constant (linear) then you can just use.

(10245458756 / 60000t)/1000 = kb/second
or
(10245458756 / 60000t)/60000 = kb/minute

The general form would be.
(size_of_file / download_speed * time) / convert_to_units

Where t (or time) is the amount of seconds that the download has been active.


On Sun, Nov 15, 2009 at 15:39, Chris Payne wrote:
> Hi everyone,
>
> I'm not sure of the correct formula for this, if I have a file - just
> for example, that is 10245458756 bytes long and the download speed is
> 60KB a second, what formula would I use to calculate how many
> seconds/minutes/hours it would take to download the file?
>
> Maths really isn't my strong point and formulas go over my head
> otherwise I wouldn't ask :-(
>
> Thanks everyone
>
> Chris
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
- Adam Shannon ( http://ashannon.us )

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php