walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.12k stars 2.26k forks source link

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

Open shizzic opened 1 year ago

shizzic commented 1 year ago

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).

Chance-fyi commented 1 year ago

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