RateLimiter
Less than 1 minute
RateLimiter
Class RateLimiter.
This class is responsible for rate limiting HTTP requests.
- Full name:
\Hazaar\RateLimiter
Properties
backend
private \Hazaar\RateLimiter\Backend $backend
windowLength
private int $windowLength
requestLimit
private int $requestLimit
requestMinimumPeriod
private int $requestMinimumPeriod
headers
private array<string,string> $headers
Methods
__construct
RateLimiter constructor.
public __construct(array $options, null|\Hazaar\RateLimiter\Backend $backend = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$options | array | the options for the rate limiter |
$backend | null|\Hazaar\RateLimiter\Backend | the backend to use for the rate limiter |
getInfo
Retrieves information about a specific identifier.
public getInfo(string $identifier): array{attempts: int, limit: int, window: int, remaining: int, identifier: string}
Parameters:
Parameter | Type | Description |
---|---|---|
$identifier | string | the identifier to retrieve information for |
Return Value:
an array containing the information about the identifier
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 |
Return Value:
returns true if the identifier is allowed to proceed, false otherwise
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): array<string,mixed>
Parameters:
Parameter | Type | Description |
---|---|---|
$identifier | string | the identifier for the headers |
Return Value:
the headers for the specified identifier
getLastRequestTime
public getLastRequestTime(string $identifier): int
Parameters:
Parameter | Type | Description |
---|---|---|
$identifier | string |
Automatically generated on 2024-11-14