Question

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.

Was it helpful?

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.

OTHER TIPS

In symfony 4 with php > 7.1

$conn->httpRequest->getUri()->getQuery()

This return all parameters into the query, only need parse string to extract the paremeter that needs.

$conn->WebSocket->request 

replaced with

$conn->httpRequest 

which is a PSR-7 object

https://github.com/ratchetphp/Ratchet/blob/master/CHANGELOG.md

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top