ObjectPool
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
Retrieve an object from the pool.
Release an object back to the pool.
Destroy a checked-out object instead of returning it to the pool.
Destroy idle objects that exceed the maximum lifetime.
Destroy idle objects past the maximum idle time down to the retention floor.
Close the pool and destroy all idle objects.
Determine if the pool is closed.
Determine if the entire pool has exceeded its idle TTL.
Return the number of objects currently checked out.
Return the current number of objects managed by the pool.
Return the number of objects currently available in the pool.
Get the normalized pool options.
Return statistics about the pool's current state.
Create a new object for the pool.
Assert an object is currently checked out from this pool.
Return an object to the idle channel without recording user activity.
Destroy an object through the pool's single cleanup path.
Determine if an object has exceeded its maximum lifetime.
Convert seconds to nanoseconds without overflowing integer arithmetic.
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.
at line 58
object
get()
Retrieve an object from the pool.
at line 82
void
release(object $object)
Release an object back to the pool.
at line 103
void
discard(object $object)
Destroy a checked-out object instead of returning it to the pool.
at line 114
void
sweepExpired()
Destroy idle objects that exceed the maximum lifetime.
at line 134
void
trimIdle()
Destroy idle objects past the maximum idle time down to the retention floor.
at line 162
void
close()
Close the pool and destroy all idle objects.
at line 179
bool
isClosed()
Determine if the pool is closed.
at line 187
bool
isIdle()
Determine if the entire pool has exceeded its idle TTL.
at line 198
int
getBorrowedObjectNumber()
Return the number of objects currently checked out.
at line 206
int
getCurrentObjectNumber()
Return the current number of objects managed by the pool.
at line 214
int
getObjectNumberInPool()
Return the number of objects currently available in the pool.
at line 222
PoolOptions
getOptions()
Get the normalized pool options.
at line 232
array
getStats()
Return statistics about the pool's current state.
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.
at line 255
protected int
assertBorrowed(object $object)
Assert an object is currently checked out from this pool.
at line 273
protected void
requeue(object $object)
Return an object to the idle channel without recording user activity.
at line 281
protected void
destroyObject(object $object)
Destroy an object through the pool's single cleanup path.
at line 309
protected bool
exceedsMaxLifetime(object $object)
Determine if an object has exceeded its maximum lifetime.
at line 405
protected int
nanoseconds(float $seconds)
Convert seconds to nanoseconds without overflowing integer arithmetic.
at line 415
protected int
deadline(float $seconds)
Build a monotonic deadline without overflowing at long durations or uptimes.