But, even If I didn’t wanted to and looked into Go and Rust for the implementation, I figured out that WebSocket on PHP wasn’t THAT bad to work with, but there were a few caveats. Some time ago, some folks found that PHP could handle some sort of concurrency through using Generators.
The stream_socket_server function in PHP allows to create a socket that returns whatever connection goes in, as it works like a Generator, along stream_set_blocking set as non-blocking.
Now that we have very “hacky” but stable way to make async calls on PHP — at least until Fibers come in PHP 8.1 at the end of the year — the next step is to hook into the socket server, and then upgrading the incoming HTTP Request connections to WebSockets connections, keeping them open in memory.
You can use and deploy a WebSocket server in a PHP server today.