Stiphle\Throttle\LeakyBucket::getNewRatio PHP Метод

getNewRatio() защищенный Метод

Assuming we're making a request, get the ratio of requests made to requests allowed
protected getNewRatio ( string $key, integer $limit, integer $milliseconds ) : float
$key string - A unique key for what we're throttling
$limit integer - How many are allowed
$milliseconds integer - In this many milliseconds
Результат float
    protected function getNewRatio($key, $limit, $milliseconds)
    {
        $lastRequest = $this->getLastRequest($key) ?: 0;
        $lastRatio = $this->getLastRatio($key) ?: 0;
        $diff = (microtime(1) - $lastRequest) * 1000;
        $newRatio = $lastRatio - $diff;
        $newRatio = $newRatio < 0 ? 0 : $newRatio;
        $newRatio += $milliseconds / $limit;
        return $newRatio;
    }