abstract class ObjectPool implements ObjectPool

Properties

protected Channel $channel
protected array<int, true> $managed
protected array<int, true> $borrowed
protected array<int, int> $creationTimes
protected array<int, int> $releaseTimes
protected int $lastUsedAt
protected bool $closed
protected int $acquiring
protected int $creating
protected Closure|null $destroyCallback

Methods

__construct(PoolOptions $options, Closure|null $destroyCallback = null)

Create an object pool.

object
get()

Retrieve an object from the pool.

void
release(object $object)

Release an object back to the pool.

void
discard(object $object)

Destroy a checked-out object instead of returning it to the pool.

void
sweepExpired()

Destroy idle objects that exceed the maximum lifetime.

void
trimIdle()

Destroy idle objects past the maximum idle time down to the retention floor.

void
close()

Close the pool and destroy all idle objects.

bool
isClosed()

Determine if the pool is closed.

bool
isIdle()

Determine if the entire pool has exceeded its idle TTL.

int
getBorrowedObjectNumber()

Return the number of objects currently checked out.

int
getCurrentObjectNumber()

Return the current number of objects managed by the pool.

int
getObjectNumberInPool()

Return the number of objects currently available in the pool.

getOptions()

Get the normalized pool options.

array
getStats()

Return statistics about the pool's current state.

object
createObject()

Create a new object for the pool.

int
assertBorrowed(object $object)

Assert an object is currently checked out from this pool.

void
requeue(object $object)

Return an object to the idle channel without recording user activity.

void
destroyObject(object $object)

Destroy an object through the pool's single cleanup path.

bool
exceedsMaxLifetime(object $object)

Determine if an object has exceeded its maximum lifetime.

int
nanoseconds(float $seconds)

Convert seconds to nanoseconds without overflowing integer arithmetic.

int
deadline(float $seconds)

Build a monotonic deadline without overflowing at long durations or uptimes.

Details

at line 44
__construct(PoolOptions $options, Closure|null $destroyCallback = null)

Create an object pool.

Parameters

PoolOptions $options
Closure|null $destroyCallback

at line 58
object get()

Retrieve an object from the pool.

Return Value

object

at line 82
void release(object $object)

Release an object back to the pool.

Parameters

object $object

Return Value

void

at line 103
void discard(object $object)

Destroy a checked-out object instead of returning it to the pool.

Parameters

object $object

Return Value

void

at line 114
void sweepExpired()

Destroy idle objects that exceed the maximum lifetime.

Return Value

void

at line 134
void trimIdle()

Destroy idle objects past the maximum idle time down to the retention floor.

Return Value

void

at line 162
void close()

Close the pool and destroy all idle objects.

Return Value

void

at line 179
bool isClosed()

Determine if the pool is closed.

Return Value

bool

at line 187
bool isIdle()

Determine if the entire pool has exceeded its idle TTL.

Return Value

bool

at line 198
int getBorrowedObjectNumber()

Return the number of objects currently checked out.

Return Value

int

at line 206
int getCurrentObjectNumber()

Return the current number of objects managed by the pool.

Return Value

int

at line 214
int getObjectNumberInPool()

Return the number of objects currently available in the pool.

Return Value

int

at line 222
PoolOptions getOptions()

Get the normalized pool options.

Return Value

PoolOptions

at line 232
array getStats()

Return statistics about the pool's current state.

Return Value

array

at line 250
abstract protected object createObject()

Create a new object for the pool.

The factory may yield and allow another coroutine to close the pool.

Return Value

object

at line 255
protected int assertBorrowed(object $object)

Assert an object is currently checked out from this pool.

Parameters

object $object

Return Value

int

at line 273
protected void requeue(object $object)

Return an object to the idle channel without recording user activity.

Parameters

object $object

Return Value

void

at line 281
protected void destroyObject(object $object)

Destroy an object through the pool's single cleanup path.

Parameters

object $object

Return Value

void

at line 309
protected bool exceedsMaxLifetime(object $object)

Determine if an object has exceeded its maximum lifetime.

Parameters

object $object

Return Value

bool

at line 405
protected int nanoseconds(float $seconds)

Convert seconds to nanoseconds without overflowing integer arithmetic.

Parameters

float $seconds

Return Value

int

at line 415
protected int deadline(float $seconds)

Build a monotonic deadline without overflowing at long durations or uptimes.

Parameters

float $seconds

Return Value

int