How to handle 'keepAlive' in own App
Hi
Is there more documentation about 'enableKeepAlive'? I'm trying to understand how this works. I have 'keepAlive' enabled and I see ping/pong being sent and received.
in my app I have an array with all connected clients: $clients[$conn->resourceId] = $conn;
If a client disconnects and ping/pong fails, how do I know about it in my app so I can delete the connection from $clients?
It's a question I have too
I'm having an issue where this is vital. I am prototyping a midi-usb device using a Teensy 4.1 microcontroller that connects into a Ratchet server over WS over ethernet. The problem that I am having is that when the usb cable is unplugged the device powers down immediately without a graceful TCP disconnection/termination, meaning the OS on the server running ratchet doesn't know the TCP connection is lost until it times out and of course there is not a graceful Websocket disconnection within PHP at this point. This makes heartbeat handling vital. It's been a long time since I've experimented with low-level TCP errors within PHP, and in my case the websocket heartbeat mechanism would suffice for handling hard TCP disconnects.
The enableKeepAlive method in WsServer.php creates a timer that monitors connections for pings, however when a connection is no longer active this method does not raise an event higher within the API for users to handle the lost client. This is short sighted since most services will have resources assigned to each client.
https://github.com/ratchetphp/Ratchet/blob/5012dc954541b40c5599d286fd40653f5716a38f/src/Ratchet/WebSocket/WsServer.php#L210-L212