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.
No description
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 45
__construct(Container $container, ConnectionPool $pool)
No description
at line 55
void
release()
Release the connection back to the pool.
at line 63
void
discard()
Discard the connection from its pool.
at line 71
mixed
getConnection()
No description
at line 79
bool
check()
Check if the connection is valid.
at line 87
bool
reconnect()
Reconnect to the server.
at line 138
mixed
call(Closure $closure, bool $refresh = true)
Execute a closure with the connection.
at line 173
bool
isConnected()
Check if currently connected.
at line 181
bool
close()
Close the connection.
at line 211
bool
isTimeout()
Check if the connection has timed out.
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.
at line 287
protected void
clear()
Clear the connection state.
at line 311
protected LoggerInterface|null
getLogger()
Get the logger instance.
at line 323
protected void
heartbeat()
Send a heartbeat to keep the connection alive.
at line 330
protected void
sendClose(mixed $connection)
Send a close protocol message.
at line 337
abstract protected mixed
getActiveConnection()
Connect and return the active connection.