Unfortuantelly, PHP is not designed to work with WebSocket. You can connect it, but your code will be full of
while (true) and
fsock_open . And you have to have access to the shell to run the WS-server with php-cgi.
You need to choose a language that supports threads / asynchronous communication. Now on the top is Node.js. In addition, better use dedicated libraries to support older browsers, etc. If you want to create one-to-all communication (eg chat, broadcast messaging), go one step further and use one of the
Bayeuximplementations, for example: Faye.
mod_proxy_wstunnel extension adds an extra layer to the WS server. Depending on the configuration, it can support DDoS, queue, load-balancing, local port swapping, and https support. But better use this for nginx.
Websockets are events, and PHP is poorly managed with it.