PHP中的外向websocket

I'm trying to create a bot script for a third party chat service using PHP. The client-server communication is based on socket.io, but works best with websockets - and, in fact, is quite easy to replicate without socket.io in browsers that support websockets. Unlike Javascript, however, PHP can't simply use new Websocket('ws://host') and be connected. I've looked at PHP's raw(?) sockets such as fsockopen and socket_create, but I don't know what to use - socket_create comes with the luxury of socket_select, but I don't know how to use a socket of that type to target anything other than an IP address - in Javascript, the url the websocket connects to includes the session id. fsockopen, on the other hand, can connect to a url this way, but I can't find any functions for waiting until the socket has bytes available to read. Every chat room requires a new socket (and session id), due to limitations of the service, so I need to be able to have multiple sockets all listening at the same time. What's the best direction to approach this from?

Turns out the PHP manual isn't very explicit - you can connect to a url with socket_connect, it doesn't have to be an IP address. It'll be annoying to implement the entire websocket protocol by hand - but it is at least functional.