改名
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Server\Abstracts;
|
||||
|
||||
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Process;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract class CustomProcess implements \Server\SInterface\CustomProcess
|
||||
{
|
||||
|
||||
/** @var bool */
|
||||
protected bool $enableSwooleCoroutine = true;
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
*/
|
||||
public function signListen(Process $process): void
|
||||
{
|
||||
if (!$this->enableSwooleCoroutine) {
|
||||
Process::signal(SIGTERM | SIGKILL, function ($signo)
|
||||
use ($process) {
|
||||
$this->waiteExit($process);
|
||||
});
|
||||
} else {
|
||||
go(function () use ($process) {
|
||||
$data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1);
|
||||
if ($data) {
|
||||
$this->waiteExit($process);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function isWorking(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function waiteExit(Process $process): void
|
||||
{
|
||||
while ($this->isWorking()) {
|
||||
$this->sleep();
|
||||
}
|
||||
$process->exit(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function sleep(): void
|
||||
{
|
||||
if ($this->enableSwooleCoroutine) {
|
||||
Coroutine::sleep(0.1);
|
||||
} else {
|
||||
usleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,11 +22,16 @@ interface CustomProcess
|
||||
public function getProcessName(Process $process): string;
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
*/
|
||||
public function signListen(Process $process): void;
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
*/
|
||||
public function onHandler(Process $process): void;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -131,6 +131,8 @@ class ServerManager
|
||||
$soloProcess->name($system . '.' . $customProcess->getProcessName($soloProcess) . ' start.');
|
||||
}
|
||||
|
||||
$customProcess->signListen($soloProcess);
|
||||
|
||||
echo sprintf("\033[36m[" . date('Y-m-d H:i:s') . "]\033[0m Process %s start.", $customProcess->getProcessName($soloProcess)) . PHP_EOL;
|
||||
$customProcess->onHandler($soloProcess);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user