KeepaliveConnection
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
Release the connection back to the pool.
Discard the connection from its pool.
Get the underlying connection.
Check if the connection is valid.
Reconnect to the server.
Check if currently connected.
Close the connection.
Check if the connection has timed out.
Add a heartbeat timer when heartbeat is enabled.
Clear the connection state.
Get the logger instance.
Send a heartbeat to keep the connection alive.
Send a close protocol message.
Connect and return the active connection.
Details
at line 47
__construct(Container $container, ConnectionPool $pool)
No description
at line 57
void
release()
Release the connection back to the pool.
at line 65
void
discard()
Discard the connection from its pool.
at line 75
mixed
getConnection()
Get the underlying connection.
at line 84
bool
check()
Check if the connection is valid.
at line 92
bool
reconnect()
Reconnect to the server.
at line 145
mixed
call(Closure $closure, bool $refresh = true)
Execute a closure with the connection.
at line 180
bool
isConnected()
Check if currently connected.
at line 188
bool
close()
Close the connection.
at line 218
bool
isTimeout()
Check if the connection has timed out.
at line 237
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.
at line 293
protected void
clear()
Clear the connection state.
at line 317
protected LoggerInterface|null
getLogger()
Get the logger instance.
at line 329
protected void
heartbeat()
Send a heartbeat to keep the connection alive.
at line 336
protected void
sendClose(mixed $connection)
Send a close protocol message.
at line 343
abstract protected mixed
getActiveConnection()
Connect and return the active connection.