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
ファイルを表示 Open project: davedevelopment/stiphle

Protected Properties

Property Type Description
$storage Stiphle\Storage\StorageInterface

Public Methods

Method 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

Protected Methods

Method 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 method

public __construct ( )

getEstimate() public method

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
return integer - the number of milliseconds before this request should be allowed to pass

getLastRatio() protected method

Get Last Ratio
protected getLastRatio ( string $key ) : float
$key string
return float

getLastRequest() protected method

Get Last Request
protected getLastRequest ( string $key ) : float
$key string
return float

getNewRatio() protected method

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
return float

getStorageKey() protected method

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
return string

setLastRatio() protected method

Set Last Ratio
protected setLastRatio ( string $key, float $ratio ) : void
$key string
$ratio float
return void

setLastRequest() protected method

Set Last Request
protected setLastRequest ( string $key, float $request ) : void
$key string
$request float
return void

setStorage() public method

Set Storage
public setStorage ( Stiphle\Storage\StorageInterface $storage ) : LeakyBucket
$storage Stiphle\Storage\StorageInterface
return LeakyBucket

throttle() public method

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
return void

Property Details

$storage protected_oe property

protected StorageInterface,Stiphle\Storage $storage
return Stiphle\Storage\StorageInterface