Reputation: 327
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..
Upvotes: 0
Views: 152
Reputation: 151
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();
Upvotes: 0