变更
This commit is contained in:
@@ -142,8 +142,6 @@ class AsyncServer implements ServerInterface
|
||||
/**
|
||||
* @param SConfig $config
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addListener(SConfig $config): void
|
||||
@@ -217,12 +215,14 @@ class AsyncServer implements ServerInterface
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @throws
|
||||
*/
|
||||
public function start(): void
|
||||
{
|
||||
$pid = (int)file_get_contents(storage('.swoole.pid'));
|
||||
if (posix_kill($pid, 0)) {
|
||||
posix_kill($pid, SIGTERM);
|
||||
}
|
||||
$processManager = Kiri::getDi()->get(EventDispatch::class);
|
||||
$processManager->dispatch(new OnServerBeforeStart());
|
||||
$this->server->start();
|
||||
|
||||
+20
-10
@@ -49,10 +49,10 @@ class HotReload extends Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->startProcess();
|
||||
pcntl_signal(SIGINT | SIGQUIT | SIGTERM, function () {
|
||||
Process::wait();
|
||||
$this->stopProcess();
|
||||
});
|
||||
$this->startProcess();
|
||||
if (extension_loaded('inotify')) {
|
||||
$this->onInotifyReload();
|
||||
} else {
|
||||
@@ -70,6 +70,23 @@ class HotReload extends Command
|
||||
$this->process = proc_open([PHP_BINARY, APP_PATH . 'kiri.php', 'sw:server', 'start'], [], $pipes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function stopProcess(): void
|
||||
{
|
||||
if (!is_resource($this->process)) {
|
||||
return;
|
||||
}
|
||||
$pid = (int)file_get_contents(storage('.swoole.pid'));
|
||||
if (posix_kill($pid, 0)) {
|
||||
posix_kill($pid, SIGTERM);
|
||||
}
|
||||
proc_close($this->process);
|
||||
$this->process = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
@@ -268,14 +285,7 @@ class HotReload extends Command
|
||||
public function trigger_reload(): void
|
||||
{
|
||||
echo 'tigger server Reload' . PHP_EOL;
|
||||
if (is_resource($this->process)) {
|
||||
$pid = (int)file_get_contents(storage('.swoole.pid'));
|
||||
if (posix_kill($pid, 0)) {
|
||||
posix_kill($pid, SIGTERM);
|
||||
}
|
||||
proc_close($this->process);
|
||||
}
|
||||
$this->process = null;
|
||||
$this->stopProcess();
|
||||
$this->startProcess();
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,6 @@ class Server
|
||||
|
||||
/**
|
||||
* @param OnTaskerStart $onWorkerStart
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function setTaskerName(OnTaskerStart $onWorkerStart): void
|
||||
{
|
||||
@@ -151,7 +150,6 @@ class Server
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onHotReload(): void
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Kiri\Server;
|
||||
use Exception;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Kiri\Server\Abstracts\TraitServer;
|
||||
use Swoole\Process;
|
||||
|
||||
@@ -22,6 +23,7 @@ class State extends Component
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
Logger::emergency();
|
||||
$this->servers = Config::get('server.ports');
|
||||
}
|
||||
|
||||
@@ -46,7 +48,7 @@ class State extends Component
|
||||
* @param $port
|
||||
* @throws Exception
|
||||
*/
|
||||
public function exit($port)
|
||||
public function exit($port): void
|
||||
{
|
||||
if (!($pid = checkPortIsAlready($port))) {
|
||||
return;
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@
|
||||
"psr/http-message": "^1.0",
|
||||
"psr/event-dispatcher": "^1.0",
|
||||
"ext-inotify": "*",
|
||||
"ext-posix": "*"
|
||||
"ext-posix": "*",
|
||||
"ext-pcntl": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
Reference in New Issue
Block a user