Compare commits

...

13 Commits

Author SHA1 Message Date
as2252258 a7db58d7e4 改名 2021-11-24 17:07:35 +08:00
as2252258 87e4bfdbec 改名 2021-11-24 17:07:13 +08:00
as2252258 ee761817bf 1 2021-11-21 01:30:49 +08:00
as2252258 4a4b7db651 1 2021-11-20 02:33:53 +08:00
as2252258 905427bccc 1 2021-11-20 02:30:13 +08:00
as2252258 68ee0244a2 1 2021-11-20 02:27:25 +08:00
as2252258 7e43775b04 改名 2021-11-19 18:27:17 +08:00
as2252258 dd4e9be06a 改名 2021-11-19 18:25:54 +08:00
as2252258 73b01c288b 改名 2021-11-19 18:23:06 +08:00
as2252258 f4f48ebad7 改名 2021-11-19 18:21:59 +08:00
as2252258 ef95f912cb 改名 2021-11-19 18:19:02 +08:00
as2252258 8bbb6adcc7 改名 2021-11-19 18:15:05 +08:00
as2252258 a855765365 改名 2021-11-19 18:13:48 +08:00
7 changed files with 29 additions and 104 deletions
+5 -4
View File
@@ -21,16 +21,17 @@
"ext-xml": "*",
"ext-curl": "*",
"ext-openssl": "*",
"symfony/console": "^v5.3",
"symfony/console": "v5.3.10",
"psr/log": "1.*",
"ext-sockets": "*",
"ext-pcntl": "*",
"ext-posix": "*",
"composer-runtime-api": "^2.0",
"swiftmailer/swiftmailer": "^6.0",
"swiftmailer/swiftmailer": "v6.3.*",
"psr/container": "^2.0",
"psr/http-server-middleware": "^1.0",
"game-worker/kiri-event": "v1.0"
"psr/http-server-middleware": "1.0.1",
"game-worker/kiri-event": "v1.0",
"ext-inotify": "*"
},
"autoload": {
"psr-4": {
+8 -9
View File
@@ -138,17 +138,16 @@ class HotReload extends Command
public function trigger_reload()
{
$this->logger->warning('change reload');
// $pid = file_get_contents(storage('.swoole.pid'));
// if (!empty($pid) && Process::kill($pid, 0)) {
// Process::kill($pid, SIGTERM);
// }
if ($this->process && Process::kill($this->process->pid, 0)) {
Process::kill($this->process->pid) && Process::wait(true);
}
$this->process = new Process(function (Process $process) {
$pid = $this->process?->pid;
$process = new Process(function (Process $process) {
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);
});
$this->process->start();
$process->start();
if ($pid && Process::kill($pid, 0)) {
Process::kill($pid) && Process::wait(true);
}
$this->process = null;
$this->process = $process;
}
+13 -13
View File
@@ -4,6 +4,7 @@ namespace Kiri\FileListen;
use Exception;
use Swoole\Event;
use Swoole\Timer;
class Inotify
{
@@ -14,6 +15,9 @@ class Inotify
private array $watchFiles = [];
protected bool $isReloading = FALSE;
protected int $cid;
const IG_DIR = [APP_PATH . 'commands', APP_PATH . '.git', APP_PATH . '.gitee'];
@@ -51,21 +55,19 @@ class Inotify
}
/**
* 开始监听
* @throws Exception
*/
/**
* 开始监听
* @throws Exception
*/
public function check()
{
if (!($events = inotify_read($this->inotify))) {
return;
}
if ($this->process->isReloading) {
if (!$this->process->isReloadingOut) {
$this->process->isReloadingOut = true;
}
if ($this->isReloading) {
return;
}
$LISTEN_TYPE = [IN_CREATE, IN_DELETE, IN_MODIFY, IN_MOVED_TO, IN_MOVED_FROM];
foreach ($events as $ev) {
if (!in_array($ev['mask'], $LISTEN_TYPE)) {
@@ -73,8 +75,8 @@ class Inotify
}
//非重启类型
if (str_ends_with($ev['name'], '.php')) {
sleep(2);
$this->reload();
Timer::after(3000, fn()=>$this->reload());
$this->isReloading = TRUE;
}
}
}
@@ -84,15 +86,13 @@ class Inotify
*/
public function reload()
{
$this->process->isReloading = true;
$this->process->trigger_reload();
$this->clearWatch();
foreach ($this->dirs as $root) {
$this->watch($root);
}
$this->process->int = -1;
$this->process->isReloading = FALSE;
$this->process->isReloadingOut = FALSE;
$this->isReloading = FALSE;
}
+3
View File
@@ -103,6 +103,9 @@ class Scaner
*/
public function timerReload()
{
if ($this->process->isReloading) {
return;
}
$this->process->isReloading = true;
$this->process->trigger_reload();
-8
View File
@@ -1,8 +0,0 @@
<?php
namespace Kiri\Proxy;
abstract class AProxy
{
}
-53
View File
@@ -1,53 +0,0 @@
<?php
namespace Kiri\Proxy;
use Annotation\Aspect;
use Http\Handler\Handler;
use Kiri\Di\NoteManager;
use Kiri\IAspect;
use Kiri\Kiri;
/**
*
*/
class AspectProxy extends AProxy implements ProxyInterface
{
/**
* @param Handler $executor
* @return mixed
*/
public function proxy(Handler $executor): mixed
{
if ($executor->callback instanceof \Closure) {
return call_user_func($executor->callback, ...$executor->params);
}
$controller = Kiri::getDi()->get($executor->callback[0]);
$aspect = $this->getAspect($executor->callback);
if (!is_null($aspect)) {
$aspect->before();
$result = $aspect->invoke([$controller, $executor->callback[1]], $executor->params);
$aspect->after($result);
} else {
$result = call_user_func([$controller, $executor->callback[1]]);
}
return $result;
}
/**
* @param array $executor
* @return ?IAspect
*/
protected function getAspect(array $executor): ?IAspect
{
$aspect = NoteManager::getSpecify_annotation(Aspect::class, $executor[0], $executor[1]);
if (!is_null($aspect)) {
$aspect = Kiri::getDi()->get($aspect->aspect);
}
return $aspect;
}
}
-17
View File
@@ -1,17 +0,0 @@
<?php
namespace Kiri\Proxy;
use Http\Handler\Handler;
interface ProxyInterface
{
/**
* @param Handler $executor
* @return mixed
*/
public function proxy(Handler $executor): mixed;
}