> > I'm not sure that would work well for Web Sockets, because it still > relies on the traditional request-response cycle, but I've never really > used them, so don't know what kind of architectural patterns make sense for > them. > > Considering the Swoole PHP extension (https://www.swoole.co.uk) the > long-running process would take the place of its functionality and new apis > to communicate with a long running process could allow communication that > resulted in regular requests being able to send messages via the web socket > server, and read queued messages from the web socket server. > > You won't be able to process notifications to clients via > request-response, but where that is needed it would be done by the > long-running process. So the request-response might "register" a > notification listener to the long-running process, for example. >
A web socket is just a way of re-using the tcp connection from a http request and holding it open for bidirectional communication. Due to this you can make assumptions about performance charicteristics from other long running socket server approaches. >From what i understand, the main problem with using fork or a thread pool for handling sockets syncroniously is overhead caused by the switching between userspace and os kernel space, as well as high memory overhead. Using fork would have the same behaviour as something like apache prefork. Handling a long running connection entails a process per connection, which could mean an awful lot of processes. Pretty much everything seems to be switching to async io based on some event loop, as it allows a single process to handle requests from a large number of connections, and long tunning but sparsely used connections don't require holding processes open that are mostly doing nothing. Based on what i see from the direction things are going in other languages, just 'getting with the times' and switching to an event based model probably makes the most sense. Anyway, i think PHP really needs to be able to handle web sockets in core.