Author: Dave Marshall (david.marshall@atstsolutions.co.uk)
Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Set Last Request
  *
  * @param string $key
  * @param float $request
  * @return void
  */
 protected function setLastRequest($key, $request)
 {
     return $this->storage->set($key . '::LASTREQUEST', $request);
 }