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

asked May 18, 2023 at 14:22

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();
answered Feb 28, 2024 at 7:23
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.