I was wondering, how can I shutdown a reactPHP HTTP server after a sending a response.
Currently I have a server code like this:
$loop = Factory::create();
$server = new Server($loop, function (ServerRequestInterface $request) {
var_dump($request);
return new Response(200,
array(
'Content-Type' => 'text/plain'
),
"I got ".$request->getBody()."\n");
});
$socket = new \React\Socket\Server(8070, $loop);
$server->listen($socket);
$loop->run();
And a client who perform a single request:
$loop = React\EventLoop\Factory::create();
$client = new React\Http\Browser($loop);
$client->post(
'http://localhost:8070',
array(
'Content-Type' => 'application/json'
),
json_encode($_GET)
)->then(function (ResponseInterface $response) {
echo (string)$response->getBody();
}, 'printf');
$loop->run();
Is there any event which I can use to shutdown server after responding. I don't want to use exit()
, because after shutdown I want to perform other tasks before true exit.