0

I'm trying to use Swoole context and finally have simplifyed it down to the following code

$server->on("Start", function(Server $server) { echo "OpenSwoole WebSocket Server is started at http://127.0.0.1:".config('chat_port')."\n"; Co::getContext()['total'] = 10; var_export(Co::getContext()); } 

var_export prints NULL. Should the context somehow enabled in configuration or somewhere? Can't google it..

1 Answer 1

0

The code you provided does not reproduce the problem.

$http = new Swoole\Http\Server("127.0.0.1", 9501); $http->on('request', function ($request, $response) { $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>"); }); $http->on('start', function ($server){ Co::getContext()['total'] = 10; var_dump(Co::getContext()); }); $http->start(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.