I am implementing a chat server using Ratchet. I've implemented a dispatcher that accepts service(params) type of messages encoded in json, similar to a RESTFUL call, but with websockets. So every request is parsed in the onMessage method and dispatched to its proper controller. The problem is that every message is processed by Ratchet in a serial fashion, one at a time. For example, if I add a sleep(n) inside and someone else tries to open a connection, it won't be accepted until the sleep() ends. This totally kills it for me, so I thought about forking every request, so that it runs on its own process. Now, the problem with that is that php's pcntl_fork seems to make an exact copy of everything, including the connections collection, so when I want to send a response to the client, there's no way for me to get the proper connection handler, I seem to get a copy of it, because nothing is sent to the client and no error is given.
So I thought about forking every connection instead of every request, but I'm completely lost there.
What do you guys suggest? I'm quite new on this type of php programming. All help will be much appreciated.