本文整理汇总了PHP中React\Socket\Server::shutdown方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::shutdown方法的具体用法?PHP Server::shutdown怎么用?PHP Server::shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\Socket\Server
的用法示例。
在下文中一共展示了Server::shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shutdown
/**
* Handles termination signals, so we can gracefully stop all servers.
*/
public function shutdown()
{
if ($this->inShutdown) {
return;
}
$this->inShutdown = true;
//this method is also called during startup when something crashed, so
//make sure we don't operate on nulls.
$this->output->writeln('<error>Termination received, exiting.</error>');
if ($this->controller) {
@$this->controller->shutdown();
}
if ($this->web) {
@$this->web->shutdown();
}
if ($this->loop) {
$this->loop->tick();
$this->loop->stop();
}
foreach ($this->slaves as $slave) {
if (is_resource($slave['process'])) {
proc_terminate($slave['process']);
}
if ($slave['pid']) {
//make sure its dead
posix_kill($slave['pid'], SIGKILL);
}
}
exit;
}
示例2: assertConnection
public function assertConnection(array $options, $message = null)
{
$settings = array_merge(["ip" => "0.0.0.0", "port" => 0, "startServer" => false, "match" => true], $options);
// optionally starting server
if ($settings["startServer"]) {
$serverLoop = EventLoopFactory::create();
$server = new SocketServer($serverLoop);
$server->listen($settings["port"]);
}
// client setup
$clientLoop = EventLoopFactory::create();
$dnsResolverFactory = new DnsResolverFactory();
$dns = $dnsResolverFactory->createCached("8.8.8.8", $clientLoop);
// dunno why dns is required for this shit
$connector = new SocketConnector($clientLoop, $dns);
$promise = $connector->create($settings["ip"], $settings["port"])->then(function (SocketStream $stream) {
$stream->close();
return true;
}, function (SocketConnectionException $e) {
return false;
});
$clientLoop->run();
// catching the output
$out = null;
$promise->done(function ($v) use(&$out) {
$out = $v;
});
// optionally cleaning up the server
if ($settings["startServer"]) {
$server->shutdown();
}
$this->assertEquals($out, $settings["match"], $message);
}
示例3: checkSigterm
/**
* Checks if the SIGTERM is presente in the server.
*/
protected function checkSigterm()
{
if ($this->sigterm) {
$this->loop->stop();
$this->socket->shutdown();
$this->output->writeln('The Foreman Processor has been stopped.');
}
}
示例4: handleRouterStop
public function handleRouterStop(RouterStopEvent $event)
{
if ($this->server) {
$this->server->shutdown();
}
foreach ($this->sessions as $k) {
$this->sessions[$k]->shutdown();
}
}
示例5: closure
/**
* @param Server $server
* @param LoopInterface $loop
*/
protected function closure(Server $server, LoopInterface $loop)
{
$this->logger->notice('Stopping server ...');
foreach ($this->serverPushHandlerRegistry->getPushers() as $handler) {
$handler->close();
$this->logger->info(sprintf('Stop %s push handler', $handler->getName()));
}
$server->emit('end');
$server->shutdown();
foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
if ($periodic instanceof TimerInterface && $loop->isTimerActive($periodic)) {
$loop->cancelTimer($periodic);
}
}
$loop->stop();
$this->logger->notice('Server stopped !');
}
示例6: connectionToTcpServerShouldSucceed
/** @test */
public function connectionToTcpServerShouldSucceed()
{
$capturedStream = null;
$loop = new StreamSelectLoop();
$server = new Server($loop);
$server->on('connection', $this->expectCallableOnce());
$server->on('connection', function () use($server, $loop) {
$server->shutdown();
});
$server->listen(9999);
$connector = new TcpConnector($loop);
$connector->create('127.0.0.1', 9999)->then(function ($stream) use(&$capturedStream) {
$capturedStream = $stream;
$stream->end();
});
$loop->run();
$this->assertInstanceOf('React\\Stream\\Stream', $capturedStream);
}
示例7: shutdown
/**
* Shuts down the event loop. This basically exits the process.
*/
public function shutdown()
{
if ($this->inShutdown) {
return;
}
$this->inShutdown = true;
$this->sendCurrentFiles();
$this->loop->tick();
if ($this->connection && $this->connection->isWritable()) {
$this->connection->close();
}
if ($this->server) {
@$this->server->shutdown();
}
if ($this->loop) {
$this->loop->tick();
@$this->loop->stop();
}
exit;
}
示例8: testConnect
public function testConnect()
{
$loop = new StreamSelectLoop();
$deferred = new Deferred();
$deferred->promise()->then(function ($value) use($loop) {
$this->assertEquals(1, $value);
$loop->stop();
}, function () {
$this->fail('Promise was rejected');
});
$server = new Server($loop);
$server->listen(54321, '0.0.0.0');
$server->on('connection', function (Stream $stream) use($deferred, $server) {
$deferred->resolve(1);
$server->shutdown();
});
$request = new RequestFactory();
$connector = new TcpConnector($loop);
$client = new Client($connector, $request);
$client->connect('127.0.0.1', 54321);
$loop->run();
}
示例9: quit
/**
* Quit the server.
*/
public function quit()
{
$this->logger->info("Quitting server");
$this->socket->shutdown();
}
示例10: testReturnsResponse
public function testReturnsResponse()
{
$loop = new StreamSelectLoop();
$request = new RequestFactory();
$server = new Server($loop);
$server->on('connection', function (SocketConnection $connection) use($server, $request) {
$connection->on('data', function ($data) use($connection, $request) {
$req = $request->response($data);
$response = new Response($req->getId(), ['1.0']);
$connection->write($response->write());
});
$connection->on('close', function () use($server) {
$server->shutdown();
});
});
$server->listen(54323, '127.0.0.1');
$tcp = new TcpConnector($loop);
$client = new Client($tcp, $request);
$client->connect('127.0.0.1', 54323)->then(function (Connection $connection) use($loop) {
$deferred = new Deferred();
$deferred->promise()->then(function ($value) {
$this->assertEquals(1, $value);
});
$electrum = new ElectrumClient($connection);
$electrum->getServerVersion('1.9.6', ' 0.6')->then(function () use($deferred, $connection) {
$deferred->resolve(1);
$connection->close();
}, function () use($loop) {
$loop->stop();
$this->fail();
});
});
$loop->run();
}
示例11: stop
public function stop()
{
$this->socketServer->shutdown();
parent::stop();
}
示例12: Server
{
$ui = Ui::printStatus($this->game);
$this->connection->write($ui);
echo $ui;
}
}
$loop = Factory::create();
$socket = new Server($loop);
$players = [];
$socket->on('connection', function (Connection $conn) use(&$players, $socket) {
if (count($players) < 2) {
$players[] = new PlayerConnection($conn);
}
if (count($players) == 2) {
$deferred = new Deferred();
$deferred->promise()->then(function ($results) use(&$players, $socket) {
foreach ($results as $result) {
foreach ($players as $player) {
if ($player === $result[0]) {
$player->getConnection()->end('You ' . $result[1] . PHP_EOL);
}
}
}
$socket->shutdown();
});
$game = new Game($players[0], $players[1]);
$game->start($deferred);
}
});
$socket->listen(1337, '0.0.0.0');
$loop->run();
示例13: close
/**
* Shut down the server
*/
public function close()
{
$this->server->shutdown();
}
示例14: onClose
/**
* @inheritDoc
*/
public function onClose($reason)
{
$this->socket->shutdown();
parent::onClose($reason);
}
示例15: shutdown
/**
* Stop listening
*/
public function shutdown()
{
$this->io->shutdown();
$this->observable->notifyCompleted();
}