abstract class KeepaliveConnection implements ConnectionInterface

Abstract connection that maintains a keepalive heartbeat.

Uses a timer to periodically check connection health and automatically closes idle connections.

Properties

protected Timer $timer
protected Channel $channel
protected float $lastUseTime
protected int|null $timerId
protected bool $connected
protected string $name

Methods

__construct(Container $container, Pool $pool)

No description

void
release()

Release the connection back to the pool.

void
discard()

Discard the connection from its pool.

mixed
getConnection()

No description

bool
check()

Check if the connection is valid.

bool
reconnect()

Reconnect to the server.

mixed
call(Closure $closure, bool $refresh = true)

Execute a closure with the connection.

bool
isConnected()

Check if currently connected.

bool
close()

Close the connection.

bool
isTimeout()

Check if the connection has timed out.

void
addHeartbeat()

Add a heartbeat timer when heartbeat is enabled.

void
clear()

Clear the connection state.

LoggerInterface|null
getLogger()

Get the logger instance.

void
heartbeat()

Send a heartbeat to keep the connection alive.

void
sendClose(mixed $connection)

Send a close protocol message.

mixed
getActiveConnection()

Connect and return the active connection.

Details

at line 38
__construct(Container $container, Pool $pool)

No description

Parameters

Container $container
Pool $pool

at line 48
void release()

Release the connection back to the pool.

Return Value

void

at line 56
void discard()

Discard the connection from its pool.

Return Value

void

at line 64
mixed getConnection()

No description

Return Value

mixed

Exceptions

InvalidArgumentException

at line 72
bool check()

Check if the connection is valid.

Return Value

bool

at line 80
bool reconnect()

Reconnect to the server.

Return Value

bool

at line 107
mixed call(Closure $closure, bool $refresh = true)

Execute a closure with the connection.

Parameters

Closure $closure
bool $refresh

Whether to refresh the last use time

Return Value

mixed

at line 138
bool isConnected()

Check if currently connected.

Return Value

bool

at line 146
bool close()

Close the connection.

Return Value

bool

at line 166
bool isTimeout()

Check if the connection has timed out.

Return Value

bool

at line 178
protected void addHeartbeat()

Add a heartbeat timer when heartbeat is enabled.

For keepalive connections, max_idle_time eviction is driven by this timer, so disabling heartbeat also disables background idle closing.

Return Value

void

at line 218
protected void clear()

Clear the connection state.

Return Value

void

at line 245
protected LoggerInterface|null getLogger()

Get the logger instance.

Return Value

LoggerInterface|null

at line 257
protected void heartbeat()

Send a heartbeat to keep the connection alive.

Return Value

void

at line 264
protected void sendClose(mixed $connection)

Send a close protocol message.

Parameters

mixed $connection

Return Value

void

at line 271
abstract protected mixed getActiveConnection()

Connect and return the active connection.

Return Value

mixed