/** * Get Estimate (doesn't require lock) * * How long would I have to wait to make a request? * * @param string $key - A unique key for what we're throttling * @param int $limit - How many are allowed * @param int $milliseconds - In this many milliseconds * @return int - the number of milliseconds before this request should be allowed * to pass */ public function getEstimate($key, $limit, $milliseconds) { $key = $this->getStorageKey($key, $limit, $milliseconds); $count = $this->storage->get($key); if ($count < $limit) { return 0; } return $milliseconds - microtime(1) * 1000 % (double) $milliseconds; }
/** * Get Last Request * * @param string $key * @return float */ protected function getLastRequest($key) { return $this->storage->get($key . '::LASTREQUEST'); }