class ConcurrencyLimiter

Properties

protected list<string> $slots

Precomputed slot names. Built once in the constructor.

Methods

__construct(LockProvider $store, string $name, int $maxLocks, int $releaseAfter)

Create a new concurrency limiter instance.

acquire(int $timeout, int $sleep = 250)

Acquire a lease on one of the limiter's slots, waiting up to the given timeout.

mixed
block(int $timeout, callable|null $callback = null, int $sleep = 250)

Attempt to acquire the lock for the given number of seconds.

false|Lock
claimSlot(string $id)

Attempt to acquire a slot lock.

Details

at line 35
__construct(LockProvider $store, string $name, int $maxLocks, int $releaseAfter)

Create a new concurrency limiter instance.

Parameters

LockProvider $store

the cache store instance

string $name

the name of the limiter

int $maxLocks

the allowed number of concurrent locks

int $releaseAfter

the number of seconds a slot should be maintained

at line 51
Lease acquire(int $timeout, int $sleep = 250)

Acquire a lease on one of the limiter's slots, waiting up to the given timeout.

Parameters

int $timeout
int $sleep

Return Value

Lease

Exceptions

LimiterTimeoutException

at line 84
mixed block(int $timeout, callable|null $callback = null, int $sleep = 250)

Attempt to acquire the lock for the given number of seconds.

When no callback is given, the slot is reserved fire-and-forget: it is held until the releaseAfter TTL reclaims it. Use acquire() to obtain a releasable lease instead.

Parameters

int $timeout
callable|null $callback
int $sleep

Return Value

mixed

Exceptions

LimiterTimeoutException
Throwable

at line 112
protected false|Lock claimSlot(string $id)

Attempt to acquire a slot lock.

Parameters

string $id

Return Value

false|Lock