ObjectPool
abstract class ObjectPool implements ObjectPool
Properties
| protected T> | $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 | $acquiringCount | ||
| protected int | $creatingCount | ||
| protected Closure|null | $destroyCallback |
Methods
Borrow 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 timeout.
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.
Return the number of coroutines waiting for an object.
Get the normalized pool options.
Return statistics about the pool's current state.
Create a new object for the pool.
Ensure an object is currently checked out from this pool.
Return an object to the idle channel without recording activity, or destroy it when the pool has closed.
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 49
__construct(PoolOptions $options, Closure|null $destroyCallback = null)
Create an object pool.
at line 63
object
borrow()
Borrow an object from the pool.
at line 89
void
release(object $object)
Release an object back to the pool.
at line 110
void
discard(object $object)
Destroy a checked-out object instead of returning it to the pool.
at line 121
void
sweepExpired()
Destroy idle objects that exceed the maximum lifetime.
at line 141
void
trimIdle()
Destroy idle objects past the maximum idle time down to the retention floor.
at line 169
void
close()
Close the pool and destroy all idle objects.
at line 195
bool
isClosed()
Determine if the pool is closed.
at line 203
bool
isIdleExpired()
Determine if the entire pool has exceeded its idle timeout.
at line 214
int
getBorrowedCount()
Return the number of objects currently checked out.
at line 222
int
getManagedCount()
Return the current number of objects managed by the pool.
at line 230
int
getIdleCount()
Return the number of objects currently available in the pool.
at line 238
int
getWaitingCount()
Return the number of coroutines waiting for an object.
at line 246
PoolOptions
getOptions()
Get the normalized pool options.
at line 256
array
getStats()
Return statistics about the pool's current state.
at line 275
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 280
protected int
ensureBorrowed(object $object)
Ensure an object is currently checked out from this pool.
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.
at line 311
protected void
destroyObject(object $object)
Destroy an object through the pool's single cleanup path.
at line 341
protected bool
exceedsMaxLifetime(object $object)
Determine if an object has exceeded its maximum lifetime.
at line 437
protected int
nanoseconds(float $seconds)
Convert seconds to nanoseconds without overflowing integer arithmetic.
at line 447
protected int
deadline(float $seconds)
Build a monotonic deadline without overflowing at long durations or uptimes.