class DbPool extends Pool

Database connection pool.

Extends the base Pool to create PooledConnection instances that wrap our Laravel-ported Connection class.

For in-memory SQLite, manages a shared PDO behind a single pooled owner. Non-pooled paths (Capsule, SimpleConnectionResolver) bypass this entirely and get isolated connections as expected.

Properties

protected Channel $channel from  Pool
protected PoolOptionInterface $option from  Pool
protected array<int, true> $managedConnections from  Pool
protected array<int, true> $borrowedConnections from  Pool
protected int $creating from  Pool
protected bool $closed from  Pool
protected FrequencyInterface|LowFrequencyInterface|null $frequency from  Pool
protected array $config
protected Timer|null $heartbeatTimer
protected int|null $heartbeatTimerId
protected PDO|null $sharedInMemorySqlitePdo

Shared PDO for in-memory SQLite.

Methods

__construct(Container $container, string $name)

Create a connection pool.

string
getName()

Get the pool name.

from  Pool
get()

Get a connection from the pool.

from  Pool
void
release(ConnectionInterface $connection)

Release a connection back to the pool.

from  Pool
void
discard(ConnectionInterface $connection)

Discard a borrowed connection from the pool.

from  Pool
void
flush()

Close idle connections while the total managed count exceeds the configured minimum.

from  Pool
void
checkIdleConnection()

Check one idle connection and discard it when unhealthy.

from  Pool
void
close()

Close the database pool and clear its shared resources.

bool
isClosed()

Determine if the pool is closed.

from  Pool
int
getCurrentConnections()

Get the current number of connections managed by the pool.

from  Pool
getOption()

Get the pool configuration options.

from  Pool
int
getConnectionsInChannel()

Get the number of connections currently available in the pool.

from  Pool
void
initOption(array $options = [])

Initialize pool options from configuration.

from  Pool
createConnection()

Create a new pooled connection.

popIdleConnection()

Pop and validate one idle connection.

from  Pool
void
requeueConnection(ConnectionInterface $connection)

Return an idle connection without changing its activity timestamps.

from  Pool
void
destroyConnection(ConnectionInterface $connection)

Destroy a managed connection and release its capacity.

from  Pool
void
report(Throwable|string $error)

Report a pool maintenance or cleanup failure without throwing.

from  Pool
getLogger()

Get the logger instance if available.

from  Pool
int
nanoseconds(float $seconds)

Convert seconds to nanoseconds without overflowing integer arithmetic.

from  Pool
int
deadline(float $seconds)

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

from  Pool
PDO|null
getSharedInMemorySqlitePdo()

Get the shared PDO for in-memory SQLite, or null for other drivers/configurations.

PDO
createSharedInMemorySqlitePdo()

Create the shared PDO for in-memory SQLite via the factory.

bool
isInMemorySqlite()

Check if this pool is for an in-memory SQLite database.

void
ensureNotDerivedInMemorySqlitePool(ConnectionName $name, array $config)

Ensure a derived read pool does not point at an in-memory SQLite database.

void
startHeartbeat()

Start the heartbeat timer if configured.

void
clearHeartbeat()

Clear the heartbeat timer.

void
heartbeat()

Run one heartbeat sweep over currently idle connections.

void
heartbeatConnection(PooledConnection $connection)

Heartbeat one idle connection.

void
discardHeartbeatConnection(PooledConnection $connection)

Discard an idle connection from the pool.

Details

at line 43
__construct(Container $container, string $name)

Create a connection pool.

Parameters

Container $container
string $name

in Pool at line 54
string getName()

Get the pool name.

Return Value

string

in Pool at line 62
ConnectionInterface get()

Get a connection from the pool.

Return Value

ConnectionInterface

in Pool at line 92
void release(ConnectionInterface $connection)

Release a connection back to the pool.

Parameters

ConnectionInterface $connection

Return Value

void

in Pool at line 109
void discard(ConnectionInterface $connection)

Discard a borrowed connection from the pool.

Parameters

ConnectionInterface $connection

Return Value

void

in Pool at line 118
void flush()

Close idle connections while the total managed count exceeds the configured minimum.

Return Value

void

in Pool at line 133
void checkIdleConnection()

Check one idle connection and discard it when unhealthy.

Return Value

void

at line 189
void close()

Close the database pool and clear its shared resources.

Return Value

void

in Pool at line 189
bool isClosed()

Determine if the pool is closed.

Return Value

bool

in Pool at line 197
int getCurrentConnections()

Get the current number of connections managed by the pool.

Return Value

int

in Pool at line 205
PoolOptionInterface getOption()

Get the pool configuration options.

Return Value

PoolOptionInterface

in Pool at line 213
int getConnectionsInChannel()

Get the number of connections currently available in the pool.

Return Value

int

in Pool at line 221
protected void initOption(array $options = [])

Initialize pool options from configuration.

Parameters

array $options

Return Value

void

at line 113
protected ConnectionInterface createConnection()

Create a new pooled connection.

Return Value

ConnectionInterface

in Pool at line 267
protected ConnectionInterface|false popIdleConnection()

Pop and validate one idle connection.

Return Value

ConnectionInterface|false

in Pool at line 291
protected void requeueConnection(ConnectionInterface $connection)

Return an idle connection without changing its activity timestamps.

Parameters

ConnectionInterface $connection

Return Value

void

in Pool at line 309
protected void destroyConnection(ConnectionInterface $connection)

Destroy a managed connection and release its capacity.

Parameters

ConnectionInterface $connection

Return Value

void

in Pool at line 333
protected void report(Throwable|string $error)

Report a pool maintenance or cleanup failure without throwing.

Parameters

Throwable|string $error

Return Value

void

in Pool at line 344
protected StdoutLoggerInterface|null getLogger()

Get the logger instance if available.

Return Value

StdoutLoggerInterface|null

in Pool at line 431
protected int nanoseconds(float $seconds)

Convert seconds to nanoseconds without overflowing integer arithmetic.

Parameters

float $seconds

Return Value

int

in Pool at line 441
protected int deadline(float $seconds)

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

Parameters

float $seconds

Return Value

int

at line 105
PDO|null getSharedInMemorySqlitePdo()

Get the shared PDO for in-memory SQLite, or null for other drivers/configurations.

Return Value

PDO|null

at line 146
protected PDO createSharedInMemorySqlitePdo()

Create the shared PDO for in-memory SQLite via the factory.

Uses the normal factory pipeline to get all config parsing, driver extensions, and connection setup. We then extract the PDO and let the Connection object be garbage collected.

Return Value

PDO

at line 157
protected bool isInMemorySqlite()

Check if this pool is for an in-memory SQLite database.

Return Value

bool

at line 171
protected void ensureNotDerivedInMemorySqlitePool(ConnectionName $name, array $config)

Ensure a derived read pool does not point at an in-memory SQLite database.

Parameters

ConnectionName $name
array $config

Return Value

void

at line 204
protected void startHeartbeat()

Start the heartbeat timer if configured.

Return Value

void

at line 227
protected void clearHeartbeat()

Clear the heartbeat timer.

Return Value

void

at line 240
protected void heartbeat()

Run one heartbeat sweep over currently idle connections.

Return Value

void

at line 259
protected void heartbeatConnection(PooledConnection $connection)

Heartbeat one idle connection.

Parameters

PooledConnection $connection

Return Value

void

at line 300
protected void discardHeartbeatConnection(PooledConnection $connection)

Discard an idle connection from the pool.

Parameters

PooledConnection $connection

Return Value

void