Access advanced parameters in Ratchet web socket requests

I installed Ratchet for websites in PHP. It connects perfectly to my javascript client using (ws: // localhost: 8080) and successfully send / receive messages. But I want to pass some parameters, for example (ws: // localhost: 8080? Param1 = value). I can’t determine how I can access param1 in my PHP script .

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

Or better: can I associate these parameters with ConnectionInterface $ conn. So I have them for further communication.

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

+7
source share
3 answers

Starting with a very recent update , you can now access it this way:

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

I actually ran into this problem myself. Tested this and it works great.

+13
source
 $conn->WebSocket->request 

replaced by

 $conn->httpRequest 

which is the object of PSR-7

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

+1
source

In symfony 4 with php> 7.1

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

This returns all parameters to the query, only a parsing line is needed to retrieve the necessary parameter.

0
source

All Articles