PHP Class Stiphle\Throttle\LeakyBucket

See also: http://stackoverflow.com/questions/1375501/how-do-i-throttle-my-sites-api-users
Author: Dave Marshall ([email protected])
Inheritance: implements Stiphle\Throttle\ThrottleInterface
Afficher le fichier Open project: davedevelopment/stiphle

Protected Properties

Свойство Type Description
$storage Stiphle\Storage\StorageInterface

Méthodes publiques

Méthode Description
__construct ( )
getEstimate ( string $key, integer $limit, integer $milliseconds ) : integer Get Estimate (doesn't require lock)
setStorage ( Stiphle\Storage\StorageInterface $storage ) : LeakyBucket Set Storage
throttle ( string $key, integer $limit, integer $milliseconds ) : void Throttle

Méthodes protégées

Méthode Description
getLastRatio ( string $key ) : float Get Last Ratio
getLastRequest ( string $key ) : float Get Last Request
getNewRatio ( string $key, integer $limit, integer $milliseconds ) : float Get new ratio
getStorageKey ( string $key, integer $limit, integer $milliseconds ) : string Get storage key
setLastRatio ( string $key, float $ratio ) : void Set Last Ratio
setLastRequest ( string $key, float $request ) : void Set Last Request

Method Details

__construct() public méthode

public __construct ( )

getEstimate() public méthode

How long would I have to wait to make a request?
public getEstimate ( string $key, integer $limit, integer $milliseconds ) : integer
$key string - A unique key for what we're throttling
$limit integer - How many are allowed
$milliseconds integer - In this many milliseconds
Résultat integer - the number of milliseconds before this request should be allowed to pass

getLastRatio() protected méthode

Get Last Ratio
protected getLastRatio ( string $key ) : float
$key string
Résultat float

getLastRequest() protected méthode

Get Last Request
protected getLastRequest ( string $key ) : float
$key string
Résultat float

getNewRatio() protected méthode

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
Résultat float

getStorageKey() protected méthode

Get storage key
protected getStorageKey ( string $key, integer $limit, integer $milliseconds ) : string
$key string - A unique key for what we're throttling
$limit integer - How many are allowed
$milliseconds integer - In this many milliseconds
Résultat string

setLastRatio() protected méthode

Set Last Ratio
protected setLastRatio ( string $key, float $ratio ) : void
$key string
$ratio float
Résultat void

setLastRequest() protected méthode

Set Last Request
protected setLastRequest ( string $key, float $request ) : void
$key string
$request float
Résultat void

setStorage() public méthode

Set Storage
public setStorage ( Stiphle\Storage\StorageInterface $storage ) : LeakyBucket
$storage Stiphle\Storage\StorageInterface
Résultat LeakyBucket

throttle() public méthode

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
Résultat void

Property Details

$storage protected_oe property

protected StorageInterface,Stiphle\Storage $storage
Résultat Stiphle\Storage\StorageInterface