modify plugin name

This commit is contained in:
2022-06-16 17:38:23 +08:00
parent 10de6b5246
commit 4daad7d111
22 changed files with 1206 additions and 70 deletions
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace Kiri\CoroutineServer;
use Swoole\Coroutine;
use function Co\run;
class Command
{
public array $arrays = [];
/** @var array<Server> */
private array $servers = [];
/**
* @return void
* @throws \Exception
*/
public function init(): void
{
$this->getServers();
run(function () {
$this->sig();
$waite = new Coroutine\WaitGroup();
foreach ($this->servers as $server) {
$waite->add();
$server->run($waite);
}
$waite->wait();
});
}
/**
* @return void
*/
public function sig(): void
{
Coroutine::create(function () {
$data = Coroutine::waitSignal(SIGTERM | SIGINT, -1);
if ($data) {
foreach ($this->servers as $server) {
$server->stop();
}
}
});
}
/**
* @return void
* @throws \Exception
*/
public function getServers(): void
{
foreach ($this->arrays as $array) {
if (isset($this->servers[$array['name']])) {
throw new \Exception('');
}
$server = new Server(\Kiri::getDi(), []);
$server->setReusePort($array['reuse_port']);
$server->setHost($array['host']);
$server->setPort($array['port']);
$server->setIsSsl($array['isSsl']);
$this->servers[$array['name']] = $server;
}
}
}