Compare commits

...

10 Commits

Author SHA1 Message Date
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
as2252258 3110e69350 改名 2021-11-19 17:11:17 +08:00
as2252258 4862e7e913 改名 2021-11-19 14:49:22 +08:00
as2252258 0a52bd502b 改名 2021-11-19 12:28:08 +08:00
4 changed files with 34 additions and 48 deletions
+13 -24
View File
@@ -5,8 +5,9 @@ namespace Kiri\Error;
use Exception;
use Http\Aspect\OnAspectInterface;
use Http\Aspect\OnJoinPointInterface;
use Http\Constrict\RequestInterface;
use Kiri\IAspect;
use Kiri\Kiri;
@@ -14,20 +15,24 @@ use Kiri\Kiri;
* Class LoggerAspect
* @package Kiri\Error
*/
class LoggerAspect implements IAspect
class LoggerAspect implements OnAspectInterface
{
private float $time;
/**
* @param mixed $handler
* @param array $params
* @param OnJoinPointInterface $joinPoint
* @return mixed
* @throws Exception
*/
public function invoke(mixed $handler, array $params = []): mixed
public function process(OnJoinPointInterface $joinPoint): mixed
{
return call_user_func($handler, ...$params);
$time = microtime(true);
$response = $joinPoint->process();
$this->print_runtime($time);
return $response;
}
@@ -44,20 +49,4 @@ class LoggerAspect implements IAspect
echo PHP_EOL;
}
public function before(): void
{
// TODO: Implement before() method.
$this->time = microtime(true);
}
/**
* @throws Exception
*/
public function after(mixed $response): void
{
// TODO: Implement after() method.
$this->print_runtime($this->time);
}
}
+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;
}
+10 -15
View File
@@ -47,28 +47,23 @@ class Inotify
public function clear()
{
Event::del($this->inotify);
var_dump('clear event');
Event::exit();
}
/**
* 开始监听
* @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;
}
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)) {
@@ -76,10 +71,6 @@ class Inotify
}
//非重启类型
if (str_ends_with($ev['name'], '.php')) {
if ($this->process->int !== -1) {
return;
}
usleep(200);
$this->reload();
}
}
@@ -90,7 +81,12 @@ class Inotify
*/
public function reload()
{
if ($this->process->isReloading) {
return;
}
$this->process->isReloading = true;
$this->process->trigger_reload();
$this->clearWatch();
foreach ($this->dirs as $root) {
@@ -98,7 +94,6 @@ class Inotify
}
$this->process->int = -1;
$this->process->isReloading = FALSE;
$this->process->isReloadingOut = 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();