workerman icon indicating copy to clipboard operation
workerman copied to clipboard

How to retrieve cookie from $request parametr if it's a string?

Open shizzic opened this issue 9 months ago • 1 comments

I have this example

$this->worker = new Worker('websocket://0.0.0.0:8090', $this->context);
        $this->worker->name = 'websocket';
        $this->worker->count     = 1;
        $this->worker->transport = 'ssl';

        $this->worker->onConnect = function($connection) {
            $connection->onWebSocketConnect = function ($connection, $request) {
                $connection->send($request);
            };
        };

And when i'm trying to use any method on $request like $request->cookie() i keep getting error like "Error: Call to a member function cookie() on string". Is there a build in parser for request or do i need to handle it myself? When i worked with SSE, $request seems to be normal (not string).

shizzic avatar Sep 25 '23 09:09 shizzic

What's your version of workerman? The parameters passed to onWebSocketConnect are not the same for 4.x and 5.x versions.

4.x https://github.com/walkor/workerman/blob/f7c9667c7b5387c01fa9e50ee79ed931e93ee76e/Protocols/Websocket.php#L445-L460

5.x https://github.com/walkor/workerman/blob/c9e4100f12ad3b7c40e82836d87c943219be988e/src/Protocols/Websocket.php#L386-L394

Chance-fyi avatar Oct 05 '23 01:10 Chance-fyi