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

__construct(Container $container, string $name, array $config = [])

Create a connection pool.

string
getName()

Get the pool name.

void
start()

Enable background maintenance after pool initialization succeeds.

borrow()

Borrow a connection from the pool.

void
release(Connection $connection)

Release a connection back to the pool.

void
discard(Connection $connection)

Discard a borrowed connection from the pool.

void
trimExcessIdle()

Close excess idle connections without checking their age.

void
checkIdleConnection()

Check one idle connection and discard it when unhealthy.

void
close()

Close the pool and destroy every idle connection.

bool
isClosed()

Determine if the pool is closed.

int
getManagedCount()

Get the current number of connections managed by the pool.

int
getBorrowedCount()

Return the number of connections borrowed by callers.

getOptions()

Get the pool configuration options.

int
getIdleCount()

Get the number of connections currently available in the pool.

int
getWaitingCount()

Get the number of coroutines waiting for a connection.

array
getStats()

Return the pool's current resource counts and closed state.

createUsageTracker()

Create this pool's usage policy after subclass initialization has completed.

createConnection()

Create a new connection for the pool.

Connection|false
popIdleConnection()

Pop and validate one idle connection.

void
requeueConnection(Connection $connection)

Return an idle connection without changing its activity timestamps.

void
destroyConnection(Connection $connection)

Destroy a managed connection and release its capacity.

void
report(Throwable|string $error)

Report a pool maintenance or cleanup failure without throwing.

getLogger()

Get the logger instance if available.

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.

int
ensureManaged(Connection $connection)

Ensure that a connection belongs to this pool before destroying it.

Details

at line 48
__construct(Container $container, string $name, array $config = [])

Create a connection pool.

Parameters

Container $container
string $name
array $config

at line 60
string getName()

Get the pool name.

Return Value

string

at line 68
void start()

Enable background maintenance after pool initialization succeeds.

Return Value

void

at line 84
Connection borrow()

Borrow a connection from the pool.

Return Value

Connection

at line 126
void release(Connection $connection)

Release a connection back to the pool.

Parameters

Connection $connection

Return Value

void

at line 143
void discard(Connection $connection)

Discard a borrowed connection from the pool.

Parameters

Connection $connection

Return Value

void

at line 154
void trimExcessIdle()

Close excess idle connections without checking their age.

Stop when the managed count reaches the retained minimum or no idle connections remain.

Return Value

void

at line 169
void checkIdleConnection()

Check one idle connection and discard it when unhealthy.

Return Value

void

at line 208
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.

Return Value

void

at line 243
bool isClosed()

Determine if the pool is closed.

Return Value

bool

at line 251
int getManagedCount()

Get the current number of connections managed by the pool.

Return Value

int

at line 259
int getBorrowedCount()

Return the number of connections borrowed by callers.

Return Value

int

at line 267
PoolOptions getOptions()

Get the pool configuration options.

Return Value

PoolOptions

at line 275
int getIdleCount()

Get the number of connections currently available in the pool.

Return Value

int

at line 283
int getWaitingCount()

Get the number of coroutines waiting for a connection.

Return Value

int

at line 293
array getStats()

Return the pool's current resource counts and closed state.

Return Value

array

at line 307
protected UsageTracker|null createUsageTracker()

Create this pool's usage policy after subclass initialization has completed.

Return Value

UsageTracker|null

at line 318
abstract protected Connection createConnection()

Create a new connection for the pool.

Return Value

Connection

at line 323
protected Connection|false popIdleConnection()

Pop and validate one idle connection.

Return Value

Connection|false

at line 347
protected void requeueConnection(Connection $connection)

Return an idle connection without changing its activity timestamps.

Parameters

Connection $connection

Return Value

void

at line 365
protected void destroyConnection(Connection $connection)

Destroy a managed connection and release its capacity.

Parameters

Connection $connection

Return Value

void

at line 387
protected void report(Throwable|string $error)

Report a pool maintenance or cleanup failure without throwing.

Parameters

Throwable|string $error

Return Value

void

at line 398
protected StdoutLoggerInterface|null getLogger()

Get the logger instance if available.

Return Value

StdoutLoggerInterface|null

at line 485
protected int nanoseconds(float $seconds)

Convert seconds to nanoseconds without overflowing integer arithmetic.

Parameters

float $seconds

Return Value

int

at line 495
protected int deadline(float $seconds)

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

Parameters

float $seconds

Return Value

int

at line 508
protected int ensureManaged(Connection $connection)

Ensure that a connection belongs to this pool before destroying it.

Parameters

Connection $connection

Return Value

int