Documentation

RateLimiter
in package

Table of Contents

Properties

$store  : RateLimitStoreInterface
$waitMode  : bool

Methods

__construct()  : mixed
Create a RateLimiter configured with a storage backend and a handling mode for exceeded limits.
checkBeforeRequest()  : void
Ensures the client is allowed to make the next request by enforcing per-second and per-day rate limits.
handleRateLimits()  : void
Stores remaining rate-limit counts for a client for both the one-second and 24-hour windows.
isWaitMode()  : bool
Indicates whether the limiter is configured to wait when a rate limit is exceeded.

Properties

Methods

__construct()

Create a RateLimiter configured with a storage backend and a handling mode for exceeded limits.

public __construct(RateLimitStoreInterface $store[, bool $waitMode = true ]) : mixed
Parameters
$store : RateLimitStoreInterface

storage backend for per-client rate-limit state

$waitMode : bool = true

if true, the limiter will wait until the limit window resets; if false, it will throw a RateLimitExceededException when limits are exceeded

checkBeforeRequest()

Ensures the client is allowed to make the next request by enforcing per-second and per-day rate limits.

public checkBeforeRequest(string $clientId) : void

If a window is exhausted and wait mode is enabled, pauses execution for the required seconds to clear the window; otherwise throws a RateLimitExceededException.

Parameters
$clientId : string

identifier of the client whose rate limits are checked

Tags
throws
RateLimitExceededException

if a rate limit is exceeded and wait mode is disabled

handleRateLimits()

Stores remaining rate-limit counts for a client for both the one-second and 24-hour windows.

public handleRateLimits(string $clientId, int $remainingSecond, int $remainingDay, int $timestamp) : void
Parameters
$clientId : string

Fingerprint identifying the client (e.g., certificate SHA1, serial+issuer).

$remainingSecond : int

remaining requests in the current one-second window

$remainingDay : int

remaining requests in the current 24-hour window

$timestamp : int

UNIX timestamp (seconds) when the limits were observed

isWaitMode()

Indicates whether the limiter is configured to wait when a rate limit is exceeded.

public isWaitMode() : bool
Return values
bool

true if the limiter waits until the rate-limit window expires, false otherwise

On this page

Search results