abstract class KeepaliveConnection implements Connection

Abstract connection that maintains a keepalive heartbeat.

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

Subclasses must return resources that close their underlying socket when the final reference is released. Failed or canceled cleanup may release a socket without sending the close protocol message.

Properties

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

Methods

__construct(Container $container, ConnectionPool $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 45
__construct(Container $container, ConnectionPool $pool)

No description

Parameters

Container $container
ConnectionPool $pool

at line 55
void release()

Release the connection back to the pool.

Return Value

void

at line 63
void discard()

Discard the connection from its pool.

Return Value

void

at line 71
mixed getConnection()

No description

Return Value

mixed

Exceptions

InvalidArgumentException

at line 79
bool check()

Check if the connection is valid.

Return Value

bool

at line 87
bool reconnect()

Reconnect to the server.

Return Value

bool

at line 138
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 173
bool isConnected()

Check if currently connected.

Return Value

bool

at line 181
bool close()

Close the connection.

Return Value

bool

at line 211
bool isTimeout()

Check if the connection has timed out.

Return Value

bool

at line 230
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 287
protected void clear()

Clear the connection state.

Return Value

void

at line 311
protected LoggerInterface|null getLogger()

Get the logger instance.

Return Value

LoggerInterface|null

at line 323
protected void heartbeat()

Send a heartbeat to keep the connection alive.

Return Value

void

at line 330
protected void sendClose(mixed $connection)

Send a close protocol message.

Parameters

mixed $connection

Return Value

void

at line 337
abstract protected mixed getActiveConnection()

Connect and return the active connection.

Return Value

mixed