RateLimiter
Less than 1 minute
RateLimiter
Class RateLimiter.
This class is responsible for rate limiting HTTP requests.
Properties
backend
private Backend $backend
windowLength
private int $windowLength
requestLimit
private int $requestLimit
requestMinimumPeriod
private int $requestMinimumPeriod
headers
private array $headers = array (
'X-RateLimit-Window' => '{{window}}',
'X-RateLimit-Limit' => '{{limit}}',
'X-RateLimit-Attempts' => '{{attempts}}',
'X-RateLimit-Remaining' => '{{remaining}}',
'X-RateLimit-Identifier' => '{{identifier}}',
'X-RateLimit-Cache' => '{{cache}}',
)
Methods
__construct
RateLimiter constructor.
public __construct(array $options, ?Backend $backend): void
Parameters
Parameter | Type | Description |
---|---|---|
$options | array | the options for the rate limiter |
$backend | Backend | the backend to use for the rate limiter |
getInfo
Retrieves information about a specific identifier.
public getInfo(string $identifier): void
Parameters
Parameter | Type | Description |
---|---|---|
$identifier | string | the identifier to retrieve information for |
check
Checks if the given identifier is allowed to proceed based on rate limiting rules.
public check(string $identifier): bool
Parameters
Parameter | Type | Description |
---|---|---|
$identifier | string | the identifier to check |
delete
Deletes a rate limiter entry identified by the given identifier.
public delete(string $identifier): void
Parameters
Parameter | Type | Description |
---|---|---|
$identifier | string | the identifier of the rate limiter entry to delete |
getHeaders
Retrieves the headers for the specified identifier.
public getHeaders(string $identifier): void
Parameters
Parameter | Type | Description |
---|---|---|
$identifier | string | the identifier for the headers |
getLastRequestTime
public getLastRequestTime(string $identifier): int
Parameters
Parameter | Type | Description |
---|---|---|
$identifier | string |
Generated by Hazaar API Doc Generator