Class flRequestThrottle
flRequestThrottle Class
Class to implement request throttling.
Package: fusionLib
Copyright:
Copyright (c) 2008 - 2015 fusionLib. All rights reserved.
Located at system/libs/Request/flRequestThrottle.php
Methods summary
public
|
#
__construct( flDb $db, integer $timeFrame, integer $limit, integer $maxThrottle = 0 )
Construct the object.
Parameters
- $db
- The database object.
- $timeFrame
- The time frame to track requests through in seconds e.g. 60
- $limit
- The number of requests per time frame e.g. 100
- $maxThrottle
- The maximum number of seconds to throttle a request for; 0 = no limit.
|
public
integer
|
#
getTimeFrame( )
Get the request time frame.
Get the request time frame.
Returns
integer Time frame in seconds.
|
public
integer
|
#
getLimit( )
Get the request limit.
Returns
integer The limit.
|
public
integer
|
#
getRemaining( )
Get the requests left before no more will be accepted.
Get the requests left before no more will be accepted.
Returns
integer Remaining requests.
|
public
integer
|
#
getWait( )
Get the number of seconds before requests will be accepted again.
Get the number of seconds before requests will be accepted again.
Returns
integer The number of seconds.
|
public
boolean
|
#
requestAllowed( string $key, boolean $throw = true )
Test if the request should be throttled.
Test if the request should be throttled.
Parameters
- $key
The database key e.g. client IP for a request or UUID for API
request tracking.
- $throw
- true if an exception should be thrown
Returns
boolean true if the request is permitted or false if it is denied.
Throws
|