在PHP中发送响应后关闭服务器

在PHP中发送响应后关闭服务器,php,server,reactphp,Php,Server,Reactphp,我想知道,在发送响应后如何关闭一个PHP HTTP服务器 目前,我的服务器代码如下: $loop = Factory::create(); $server = new Server($loop, function (ServerRequestInterface $request) { var_dump($request); return new Response(200, array( 'Content-Type' => 'text/

我想知道,在发送响应后如何关闭一个PHP HTTP服务器

目前,我的服务器代码如下:

$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();
以及执行单个请求的客户端:

$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();

是否有任何事件可用于在响应后关闭服务器。我不想使用
exit()。当您执行此操作时,套接字将停止侦听传入的连接,因此,事件循环将停止。

我已通过发送第二个请求解决了此问题,该请求将在服务器上解析为“关机调用”。第二个请求在收到第一个请求的响应后立即发送。