Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5defd5fb30 | |||
| 95f52b58fd | |||
| 0a97c9b29a | |||
| 3336573b4d | |||
| 44187c2354 | |||
| a058f3ed99 | |||
| faff485006 | |||
| e2b012126a | |||
| b36e21d8ee | |||
| d191296ecc | |||
| 03825dcb09 |
@@ -149,9 +149,7 @@ class HotReload extends AbstractProcess
|
||||
public function readFile(string $directory): void
|
||||
{
|
||||
if (str_ends_with($directory, '.php') === true) {
|
||||
$wd = inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
|
||||
|
||||
$this->watches[] = $wd;
|
||||
inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kiri\Server\Handler;
|
||||
|
||||
use Kiri;
|
||||
use Kiri\Server\Abstracts\Server;
|
||||
use Kiri\Server\Contract\OnPipeMessageInterface;
|
||||
|
||||
@@ -20,13 +21,17 @@ class OnPipeMessage extends Server
|
||||
*/
|
||||
public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message): void
|
||||
{
|
||||
if (is_string($message)) {
|
||||
$message = unserialize($message);
|
||||
try {
|
||||
if (is_string($message)) {
|
||||
$message = unserialize($message);
|
||||
}
|
||||
if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) {
|
||||
return;
|
||||
}
|
||||
call_user_func([$message, 'process'], $server, $src_worker_id);
|
||||
} catch (\Throwable $throwable) {
|
||||
Kiri::getLogger()->error(throwable($throwable));
|
||||
}
|
||||
if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) {
|
||||
return;
|
||||
}
|
||||
call_user_func([$message, 'process'], $server, $src_worker_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Kiri\Server\Processes;
|
||||
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Process;
|
||||
use const SIGHUP;
|
||||
use const SIGTERM;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -125,26 +127,29 @@ abstract class AbstractProcess implements OnProcessInterface
|
||||
{
|
||||
$this->process = $process;
|
||||
if ($this->enable_coroutine) {
|
||||
Coroutine::set([
|
||||
'enable_deadlock_check' => false,
|
||||
'deadlock_check_disable_trace' => false,
|
||||
'exit_condition' => function () {
|
||||
return Coroutine::stats()['coroutine_num'] === 0;
|
||||
}
|
||||
]);
|
||||
Coroutine::create(fn () => $this->coroutineWaitSignal());
|
||||
$array['enable_deadlock_check'] = false;
|
||||
$array['deadlock_check_disable_trace'] = false;
|
||||
$array['exit_condition'] = [$this, 'exit_condition'];
|
||||
Coroutine::set($array);
|
||||
Coroutine::create(fn() => $this->coroutineWaitSignal());
|
||||
} else {
|
||||
pcntl_signal(SIGTERM, [$this, 'pointWaitSignal']);
|
||||
pcntl_signal(SIGTERM | SIGINT | SIGUSR1, [$this, 'pointWaitSignal']);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function exit_condition(): bool
|
||||
{
|
||||
return Coroutine::stats()['coroutine_num'] === 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $signal
|
||||
* @return void
|
||||
*/
|
||||
public function pointWaitSignal($data): void
|
||||
public function pointWaitSignal($signal): void
|
||||
{
|
||||
$this->stop = true;
|
||||
|
||||
|
||||
+4
-2
@@ -77,8 +77,10 @@ class Task
|
||||
if (is_null($data)) {
|
||||
return null;
|
||||
}
|
||||
$data[0] = Kiri::getDi()->get($data[0]);
|
||||
return call_user_func($data, $task_id, $src_worker_id);
|
||||
[$handler, $params] = [$data[0], $data[1]];
|
||||
|
||||
$handler[0] = Kiri::getDi()->get($handler[0]);
|
||||
return call_user_func($handler, $task_id, $src_worker_id, $params);
|
||||
} catch (\Throwable $throwable) {
|
||||
return $this->exception->emit($throwable, response());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user