Stiphle\Throttle\TimeWindow::throttle PHP Метод

throttle() публичный Метод

Throttle
public throttle ( string $key, integer $limit, integer $milliseconds ) : void
$key string - A unique key for what we're throttling
$limit integer - How many are allowed
$milliseconds integer - In this many milliseconds
Результат void
    public function throttle($key, $limit, $milliseconds)
    {
        /**
         * Try do our waiting without a lock, so may sneak through because of
         * this...
         */
        $wait = $this->getEstimate($key, $limit, $milliseconds);
        if ($wait > 0) {
            usleep($wait * 1000);
        }
        $key = $this->getStorageKey($key, $limit, $milliseconds);
        $this->storage->lock($key);
        $count = $this->storage->get($key);
        $count++;
        $this->storage->set($key, $count);
        $this->storage->unlock($key);
        return $wait;
    }