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
zzmaster
3271 gold badge6 silver badges17 bronze badges
1 Answer 1
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
lang-php