Ratchet
Ratchet copied to clipboard
Graceful stop is not possible with enableKeepAlive
Hi.
As much as I have seen throughout examples and issue comments, the only advertised way to stop running server is to call EventLoop::stop()
. I agree that it's a perfectly viable solution, however ReactPHP docs state that usage of this method is not recommended to stop the loop, and there are projects that rely on automatic loop termination istead.
The problem I encountered is that enableKeepAlive()
created periodic timer that is never ever cancelled, resulting in websocket server never terminating without call to EventLoop::stop()
(which I do not rely on).
I would suggest adding another method that would disable keep-alive and cancel periodic timer.
A workaround I use is to create a timer with 0.1 second timeout that would call EventLoop::stop()
. But this is not as alegant as it could be.
What's the use case you'd want stop a running WebSocket server without ending the Unix process?
The use case is running asynchronous pre-terminate tasks after websocket server has stopped listening for incoming connection.
I'm thinking if we return
the timer object from enableKeepAlive
you could then call cancelTimer
with it. Would that work for you?
That certainly would work.