ConnectionPool
abstract class ConnectionPool implements ConnectionPool
Manage reusable connections with explicit ownership and terminal teardown.
Properties
| protected Connection> | $channel | ||
| protected PoolOptions | $options | ||
| protected array<int, true> | $managedConnections | ||
| protected array<int, true> | $borrowedConnections | ||
| protected int | $creatingCount | ||
| protected bool | $closed | ||
| protected UsageTracker|null | $usageTracker | ||
| protected bool | $usageTrackerInitialized | ||
| protected IdleConnectionMonitor|null | $idleMonitor |
Methods
Get the pool name.
Enable background maintenance after pool initialization succeeds.
Borrow a connection from the pool.
Close excess idle connections without checking their age.
Check one idle connection and discard it when unhealthy.
Close the pool and destroy every idle connection.
Determine if the pool is closed.
Get the current number of connections managed by the pool.
Return the number of connections borrowed by callers.
Get the pool configuration options.
Get the number of connections currently available in the pool.
Get the number of coroutines waiting for a connection.
Return the pool's current resource counts and closed state.
Create this pool's usage policy after subclass initialization has completed.
Create a new connection for the pool.
Pop and validate one idle connection.
Return an idle connection without changing its activity timestamps.
Get the logger instance if available.
Convert seconds to nanoseconds without overflowing integer arithmetic.
Build a monotonic deadline without overflowing at long durations or uptimes.
Ensure that a connection belongs to this pool before destroying it.
Details
at line 49
__construct(Container $container, string $name, array $config = [])
Create a connection pool.
at line 61
string
getName()
Get the pool name.
at line 69
void
start()
Enable background maintenance after pool initialization succeeds.
at line 85
Connection
borrow()
Borrow a connection from the pool.
at line 129
void
release(Connection $connection)
Release a connection back to the pool.
at line 146
void
discard(Connection $connection)
Discard a borrowed connection from the pool.
at line 157
void
trimExcessIdle()
Close excess idle connections without checking their age.
Stop when the managed count reaches the retained minimum or no idle connections remain.
at line 172
void
checkIdleConnection()
Check one idle connection and discard it when unhealthy.
at line 213
void
close()
Close the pool and destroy every idle connection.
Idempotent. Connections borrowed when closure begins are destroyed on release, and factories completing after closure destroy their orphan.
at line 254
bool
isClosed()
Determine if the pool is closed.
at line 262
int
getManagedCount()
Get the current number of connections managed by the pool.
at line 270
int
getBorrowedCount()
Return the number of connections borrowed by callers.
at line 278
PoolOptions
getOptions()
Get the pool configuration options.
at line 286
int
getIdleCount()
Get the number of connections currently available in the pool.
at line 294
int
getWaitingCount()
Get the number of coroutines waiting for a connection.
at line 304
array
getStats()
Return the pool's current resource counts and closed state.
at line 318
protected UsageTracker|null
createUsageTracker()
Create this pool's usage policy after subclass initialization has completed.
at line 329
abstract protected Connection
createConnection()
Create a new connection for the pool.
at line 334
protected Connection|false
popIdleConnection()
Pop and validate one idle connection.
at line 358
protected void
requeueConnection(Connection $connection)
Return an idle connection without changing its activity timestamps.
at line 376
protected void
destroyConnection(Connection $connection)
Destroy a managed connection and release its capacity.
at line 400
protected void
report(Throwable|string $error)
Report a pool maintenance or cleanup failure without throwing.
at line 411
protected StdoutLoggerInterface|null
getLogger()
Get the logger instance if available.
at line 498
protected int
nanoseconds(float $seconds)
Convert seconds to nanoseconds without overflowing integer arithmetic.
at line 508
protected int
deadline(float $seconds)
Build a monotonic deadline without overflowing at long durations or uptimes.
at line 521
protected int
ensureManaged(Connection $connection)
Ensure that a connection belongs to this pool before destroying it.