Files
kiri-http-server/State.php
T

57 lines
779 B
PHP
Raw Normal View History

2021-12-01 16:09:49 +08:00
<?php
namespace Server;
use Exception;
2021-12-03 15:42:04 +08:00
use Kiri\Abstracts\Component;
2021-12-01 16:09:49 +08:00
use Kiri\Abstracts\Config;
use Swoole\Process;
2021-12-03 15:42:04 +08:00
class State extends Component
2021-12-01 16:09:49 +08:00
{
use TraitServer;
public array $servers = [];
public function init()
{
2021-12-01 17:21:15 +08:00
$this->servers = Config::get('server.ports');
2021-12-01 16:09:49 +08:00
}
/**
* @return bool
* @throws Exception
*/
public function isRunner(): bool
{
$ports = $this->sortService($this->servers);
foreach ($ports as $config) {
if (checkPortIsAlready($config['port'])) {
return true;
}
}
return false;
}
/**
* @param $port
* @throws Exception
*/
public function exit($port)
{
if (!($pid = checkPortIsAlready($port))) {
return;
}
while (checkPortIsAlready($port)) {
Process::kill($pid, SIGTERM);
usleep(300);
}
}
}