phpwebsocketratchet

Access extra parameters in Ratchet web socket requests


I've set up Ratchet for websockets in PHP . It is connecting fine from my javascript client using (ws://localhost:8080) and successfully send/receive messages. But I want to pass some params like (ws://localhost:8080?param1=value). I'm not able to figure out how can I access param1 in my PHP script.

If possible in MessageComponentInterface::onOpen(ConnectionInterface $conn) method.

Or better: Can I associate those params with ConnectionInterface $conn. So that I've them for further communication.

I've followed http://socketo.me/docs/hello-world.


Solution

  • As of a very recent update, you can now access this like so:

    function onOpen( ConnectionInterface $conn ) {
       $querystring = $conn->WebSocket->request->getQuery();
    }
    

    I actually just ran into this issue myself. Tested this and it's working perfectly.