class CallbackObjectPool extends ObjectPool

Properties

protected T> $channel from  ObjectPool
protected array<int, true> $managed from  ObjectPool
protected array<int, true> $borrowed from  ObjectPool
protected array<int, int> $creationTimes from  ObjectPool
protected array<int, int> $releaseTimes from  ObjectPool
protected int $lastUsedAt from  ObjectPool
protected bool $closed from  ObjectPool
protected int $acquiringCount from  ObjectPool
protected int $creatingCount from  ObjectPool
protected Closure|null $destroyCallback from  ObjectPool
protected Closure $createCallback

Methods

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

Create an object pool using a construction callback.

object
borrow()

Borrow 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
isIdleExpired()

Determine if the entire pool has exceeded its idle timeout.

int
getBorrowedCount()

Return the number of objects currently checked out.

int
getManagedCount()

Return the current number of objects managed by the pool.

int
getIdleCount()

Return the number of objects currently available in the pool.

int
getWaitingCount()

Return the number of coroutines waiting for an object.

getOptions()

Get the normalized pool options.

array
getStats()

Return statistics about the pool's current state.

object
createObject()

Create a new object using the configured callback.

int
ensureBorrowed(object $object)

Ensure an object is currently checked out from this pool.

void
requeue(object $object)

Return an object to the idle channel without recording activity, or destroy it when the pool has closed.

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 16
__construct(callable $createCallback, PoolOptions $options, Closure|null $destroyCallback = null)

Create an object pool using a construction callback.

Parameters

callable $createCallback
PoolOptions $options
Closure|null $destroyCallback

in ObjectPool at line 63
object borrow()

Borrow an object from the pool.

Return Value

object

in ObjectPool at line 89
void release(object $object)

Release an object back to the pool.

Parameters

object $object

Return Value

void

in ObjectPool at line 110
void discard(object $object)

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

Parameters

object $object

Return Value

void

in ObjectPool at line 121
void sweepExpired()

Destroy idle objects that exceed the maximum lifetime.

Return Value

void

in ObjectPool at line 141
void trimIdle()

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

Return Value

void

in ObjectPool at line 169
void close()

Close the pool and destroy all idle objects.

Return Value

void

in ObjectPool at line 195
bool isClosed()

Determine if the pool is closed.

Return Value

bool

in ObjectPool at line 203
bool isIdleExpired()

Determine if the entire pool has exceeded its idle timeout.

Return Value

bool

in ObjectPool at line 214
int getBorrowedCount()

Return the number of objects currently checked out.

Return Value

int

in ObjectPool at line 222
int getManagedCount()

Return the current number of objects managed by the pool.

Return Value

int

in ObjectPool at line 230
int getIdleCount()

Return the number of objects currently available in the pool.

Return Value

int

in ObjectPool at line 238
int getWaitingCount()

Return the number of coroutines waiting for an object.

Return Value

int

in ObjectPool at line 246
PoolOptions getOptions()

Get the normalized pool options.

Return Value

PoolOptions

in ObjectPool at line 256
array getStats()

Return statistics about the pool's current state.

Return Value

array

at line 29
protected object createObject()

Create a new object using the configured callback.

Return Value

object

in ObjectPool at line 280
protected int ensureBorrowed(object $object)

Ensure an object is currently checked out from this pool.

Parameters

object $object

Return Value

int

in ObjectPool at line 300
protected void requeue(object $object)

Return an object to the idle channel without recording activity, or destroy it when the pool has closed.

Parameters

object $object

Return Value

void

in ObjectPool at line 311
protected void destroyObject(object $object)

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

Parameters

object $object

Return Value

void

in ObjectPool at line 341
protected bool exceedsMaxLifetime(object $object)

Determine if an object has exceeded its maximum lifetime.

Parameters

object $object

Return Value

bool

in ObjectPool at line 437
protected int nanoseconds(float $seconds)

Convert seconds to nanoseconds without overflowing integer arithmetic.

Parameters

float $seconds

Return Value

int

in ObjectPool at line 447
protected int deadline(float $seconds)

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

Parameters

float $seconds

Return Value

int