Compare commits

..

112 Commits

Author SHA1 Message Date
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
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
as2252258 95492e2863 改名 2021-11-19 11:25:50 +08:00
as2252258 3cc0a9bef2 改名 2021-11-19 11:25:06 +08:00
as2252258 d743382868 改名 2021-11-19 11:24:08 +08:00
as2252258 47f1407118 改名 2021-11-19 11:21:02 +08:00
as2252258 04395f293d 改名 2021-11-19 11:20:25 +08:00
as2252258 a44b7a31ef 改名 2021-11-19 11:19:46 +08:00
as2252258 493ef65ce8 改名 2021-11-19 11:15:40 +08:00
as2252258 3943142b86 改名 2021-11-19 11:13:32 +08:00
as2252258 786f96363b 改名 2021-11-19 11:11:40 +08:00
as2252258 bcf73a8cad 改名 2021-11-19 11:05:08 +08:00
as2252258 2b152504ec 改名 2021-11-19 11:03:55 +08:00
as2252258 e554ad3642 改名 2021-11-19 11:03:38 +08:00
as2252258 c801aec334 改名 2021-11-19 11:03:18 +08:00
as2252258 2c2c16819a 改名 2021-11-19 11:02:49 +08:00
as2252258 a48aa9a20f 改名 2021-11-19 11:02:31 +08:00
as2252258 8dadcbed16 改名 2021-11-19 11:02:08 +08:00
as2252258 86dd776388 改名 2021-11-19 11:00:10 +08:00
as2252258 d83d0871f5 改名 2021-11-19 10:59:53 +08:00
as2252258 fc6baa83a7 改名 2021-11-19 10:59:32 +08:00
as2252258 35dd2803fc 改名 2021-11-19 10:55:52 +08:00
as2252258 e3527752a7 改名 2021-11-19 10:54:30 +08:00
as2252258 340e0f1686 改名 2021-11-19 10:54:06 +08:00
as2252258 2ad6153405 改名 2021-11-19 10:41:17 +08:00
as2252258 0f172ae62d 改名 2021-11-19 10:40:49 +08:00
as2252258 f4596bf02c 改名 2021-11-19 10:37:12 +08:00
as2252258 ef4f84f696 改名 2021-11-19 10:36:55 +08:00
as2252258 08d19c9c05 改名 2021-11-19 10:36:33 +08:00
as2252258 e0537f2ee4 改名 2021-11-19 10:36:07 +08:00
as2252258 0edcf8c83f 改名 2021-11-19 10:31:43 +08:00
as2252258 6ac2c73a8c 改名 2021-11-19 10:31:26 +08:00
as2252258 b1a5db0a6b 改名 2021-11-19 10:29:46 +08:00
as2252258 8ec1a81ecd 改名 2021-11-19 10:20:49 +08:00
as2252258 b98de03317 改名 2021-11-19 10:12:53 +08:00
as2252258 251bca3d64 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	kiri-engine/FileListen/HotReload.php
2021-11-19 10:11:55 +08:00
as2252258 b2a79ef0ed 改名 2021-11-19 10:10:48 +08:00
as2252258 d9451f5087 1 2021-11-19 04:11:29 +08:00
as2252258 84d8dda8eb 1 2021-11-19 04:10:55 +08:00
as2252258 1d846a4903 1 2021-11-19 04:10:41 +08:00
as2252258 fe4f985315 1 2021-11-19 04:09:28 +08:00
as2252258 c5c1d991f2 1 2021-11-19 04:08:16 +08:00
as2252258 9ec6573ca4 1 2021-11-19 04:04:44 +08:00
as2252258 9800024d59 1 2021-11-19 04:04:36 +08:00
as2252258 57b2214433 1 2021-11-19 04:03:01 +08:00
as2252258 2f038e5637 1 2021-11-19 04:02:40 +08:00
as2252258 0f238f488d 1 2021-11-19 04:00:31 +08:00
as2252258 59243a6fed 1 2021-11-19 03:59:36 +08:00
as2252258 fbd7f874ac 1 2021-11-19 03:59:15 +08:00
as2252258 7aee3c8458 1 2021-11-19 03:59:04 +08:00
as2252258 f3446da34e 1 2021-11-19 03:57:24 +08:00
as2252258 755594b4bb 1 2021-11-19 03:54:31 +08:00
as2252258 abcf5e9feb 1 2021-11-19 03:53:57 +08:00
as2252258 f243e19b24 1 2021-11-19 03:52:44 +08:00
as2252258 5d91b61f83 1 2021-11-19 03:51:41 +08:00
as2252258 d3ed35e948 1 2021-11-19 03:50:47 +08:00
as2252258 c5bfe8110a 1 2021-11-19 03:48:54 +08:00
as2252258 1c18ee94ee 1 2021-11-19 03:48:16 +08:00
as2252258 f72c73766d 1 2021-11-19 03:46:29 +08:00
as2252258 092139c0b9 1 2021-11-19 03:46:10 +08:00
as2252258 43a1fad278 1 2021-11-19 03:45:18 +08:00
as2252258 dbc4cb15dd 1 2021-11-19 03:43:29 +08:00
as2252258 758bd650b5 1 2021-11-19 03:43:00 +08:00
as2252258 ba804c4d9c 1 2021-11-19 03:42:23 +08:00
as2252258 cac794ca20 1 2021-11-19 03:37:57 +08:00
as2252258 ea09d3e3ba 1 2021-11-19 03:36:35 +08:00
as2252258 f6552c45ae 1 2021-11-19 03:27:30 +08:00
as2252258 114f5d0279 1 2021-11-19 03:27:07 +08:00
as2252258 5638d171d0 1 2021-11-19 03:24:09 +08:00
as2252258 fa78d360b0 1 2021-11-19 03:21:21 +08:00
as2252258 ffc35090b9 1 2021-11-19 03:03:15 +08:00
as2252258 5156a606e0 1 2021-11-19 03:03:00 +08:00
as2252258 2393ef820f 1 2021-11-19 03:01:17 +08:00
as2252258 9986900b58 1 2021-11-19 02:56:34 +08:00
as2252258 07c52ef08f 1 2021-11-19 02:55:34 +08:00
as2252258 0a6fdda720 1 2021-11-19 02:54:05 +08:00
as2252258 841a6b4a19 1 2021-11-19 02:50:39 +08:00
as2252258 873da66a90 1 2021-11-19 02:20:04 +08:00
as2252258 be9f4281e6 改名 2021-11-18 19:01:11 +08:00
as2252258 57be085166 改名 2021-11-18 18:41:37 +08:00
as2252258 454c77f37a 改名 2021-11-18 17:59:46 +08:00
as2252258 323a4b8ff0 改名 2021-11-18 17:58:46 +08:00
as2252258 c66e5120e1 改名 2021-11-18 17:55:52 +08:00
as2252258 1fa7d3a3ba 改名 2021-11-18 17:50:05 +08:00
as2252258 a290108ddd 改名 2021-11-18 16:44:55 +08:00
as2252258 446fd740f2 改名 2021-11-18 16:42:24 +08:00
as2252258 a040099b99 改名 2021-11-18 16:38:55 +08:00
as2252258 78fdc7c1ca 改名 2021-11-18 16:38:43 +08:00
as2252258 dfc249b56c 改名 2021-11-18 16:31:41 +08:00
as2252258 577be309cc 改名 2021-11-18 16:30:34 +08:00
as2252258 9798be99e6 改名 2021-11-18 15:57:38 +08:00
as2252258 e3348a11c8 改名 2021-11-18 15:37:11 +08:00
as2252258 1643a839b3 改名 2021-11-18 11:37:13 +08:00
as2252258 d4a15d26ed 改名 2021-11-17 16:43:55 +08:00
as2252258 485d926dc0 改名 2021-11-17 16:39:12 +08:00
as2252258 6a5205e9a1 1 2021-11-11 02:22:14 +08:00
as2252258 471f7a92bb 1 2021-11-11 01:32:04 +08:00
as2252258 429ffe561c 改名 2021-11-08 11:12:53 +08:00
as2252258 27cdf5082f 改名 2021-11-08 11:10:58 +08:00
as2252258 4c3751ca4d 1 2021-11-07 03:18:27 +08:00
21 changed files with 341 additions and 486 deletions
+48 -1
View File
@@ -18,6 +18,7 @@ use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Psr\Log\LoggerInterface;
use Server\ServerManager;
use Swoole\Process;
use Swoole\WebSocket\Server;
if (!function_exists('make')) {
@@ -52,6 +53,38 @@ if (!function_exists('make')) {
}
if (!function_exists('checkPortIsAlready')) {
/**
* @param $port
* @return bool|string
* @throws Exception
*/
function checkPortIsAlready($port): bool|string
{
if (!Kiri::getPlatform()->isLinux()) {
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
if (empty($output)) return false;
$output = explode(PHP_EOL, $output[0]);
return $output[0];
}
$serverPid = file_get_contents(storage('.swoole.pid'));
if (!empty($serverPid) && shell_exec('ps -ef | grep ' . $serverPid . ' | grep -v grep')) {
Process::kill($serverPid, 0) && Process::kill($serverPid, SIGTERM);
}
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
if (empty($output)) {
return false;
}
return explode('/', $output[0])[0];
}
}
if (!function_exists('done')) {
/**
@@ -59,12 +92,26 @@ if (!function_exists('done')) {
*/
function done()
{
ServerManager::setEnv('state', 'exit');
set_env('state', 'exit');
}
}
if (!function_exists('set_env')) {
/**
* @param $key
* @param $value
*/
function set_env($key, $value)
{
putenv(sprintf('%s=%s', $key, $value));
}
}
if (!function_exists('enable_file_modification_listening')) {
+1 -1
View File
@@ -29,7 +29,7 @@ use Kiri\Jwt\Jwt;
use Kiri\Kiri;
use ReflectionException;
use Server\ServerManager;
use Server\SInterface\OnTaskInterface;
use Server\Contract\OnTaskInterface;
use Swoole\Table;
/**
+191 -171
View File
@@ -21,203 +21,223 @@ use Swoole\Coroutine;
class BaseObject implements Configure
{
/**
* BaseAbstract constructor.
*
* @param array $config
* @throws Exception
*/
public function __construct(array $config = [])
{
if (!empty($config) && is_array($config)) {
Kiri::configure($this, $config);
}
}
/**
* BaseAbstract constructor.
*
* @param array $config
* @throws Exception
*/
public function __construct(array $config = [])
{
if (!empty($config) && is_array($config)) {
Kiri::configure($this, $config);
}
}
/**
* @throws Exception
*/
public function init()
{
}
/**
* @throws Exception
*/
public function init()
{
}
/**
* @param array|callable $callback
* @param object $scope
*/
public function async_create(array|callable $callback, object $scope)
{
Coroutine::create($callback, $scope);
}
/**
* @param array|callable $callback
* @param object $scope
*/
public function async_create(array|callable $callback, object $scope)
{
Coroutine::create($callback, $scope);
}
/**
* @return string
*/
#[Pure] public static function className(): string
{
return static::class;
}
/**
* @return string
*/
#[Pure] public static function className(): string
{
return static::class;
}
/**
* @param $name
* @param $value
*
* @throws Exception
*/
public function __set($name, $value)
{
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$this->{$method}($value);
} else {
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $name
* @param $value
*
* @throws Exception
*/
public function __set($name, $value)
{
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$this->{$method}($value);
} else {
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $name
*
* @return mixed
* @throws Exception
*/
public function __get($name): mixed
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->$method();
} else {
throw new Exception('The get name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $name
*
* @return mixed
* @throws Exception
*/
public function __get($name): mixed
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->$method();
} else {
throw new Exception('The get name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $message
* @param string $model
* @return bool
* @throws Exception
*/
public function addError($message, string $model = 'app'): bool
{
if ($message instanceof \Throwable) {
$this->error(jTraceEx($message));
} else {
if (!is_string($message)) {
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
}
$this->error($message);
}
return FALSE;
}
/**
* @param $message
* @param string $model
* @return bool
* @throws Exception
*/
public function addError($message, string $model = 'app'): bool
{
if ($message instanceof \Throwable) {
$this->error(jTraceEx($message));
} else {
if (!is_string($message)) {
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
}
$this->error($message);
}
return FALSE;
}
/**
* @return Logger
* @throws Exception
*/
private function logger(): Logger
{
return Kiri::getDi()->get(Logger::class);
}
/**
* @return Logger
* @throws Exception
*/
private function logger(): Logger
{
return Kiri::getDi()->get(Logger::class);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function debug(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[35m[" . date('Y-m-d H:i:s') . '][DEBUG]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$this->logger()->debug(Logger::DEBUG, [$message, $method, $file]);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function debug(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[35m" . $message . "\033[0m";
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function info(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[34m[" . date('Y-m-d H:i:s') . '][INFO]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->info(Logger::NOTICE, [$message, $method, $file]);
}
$this->logger()->debug($message, $context);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function success(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[36m[" . date('Y-m-d H:i:s') . '][SUCCESS]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$this->logger()->notice(Logger::NOTICE, [$message, $method, $file]);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function info(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[34m" . $message . "\033[0m";
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function warning(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$message = "\033[33m[" . date('Y-m-d H:i:s') . '][WARNING]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$this->logger()->critical(Logger::NOTICE, [$message, $method, $file]);
}
$this->logger()->info($message, $context);
}
/**
* @param mixed $message
* @param null $method
* @param null $file
* @throws Exception
*/
public function error(mixed $message, $method = null, $file = null)
{
if ($message instanceof \Throwable) {
$message = $message->getMessage() . " on line " . $message->getLine() . " at file " . $message->getFile();
}
$content = (empty($method) ? '' : $method . ': ') . $message;
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function success(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[41;37m[" . date('Y-m-d H:i:s') . '][ERROR]: ' . $content . "\033[0m";
$message = "\033[36m" . $message . "\033[0m";
if (!empty($file)) {
$message .= PHP_EOL . "\033[41;37m[" . date('Y-m-d H:i:s') . '][ERROR]: ' . $file . "\033[0m";
}
$this->logger()->error(Logger::ERROR, [$message, $method, $file]);
}
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->notice($message, $context);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function warning(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[33m" . $message . "\033[0m";
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->critical($message, $context);
}
/**
* @param mixed $message
* @param null $method
* @param null $file
* @throws Exception
*/
public function error(mixed $message, $method = null, $file = null)
{
if ($message instanceof \Throwable) {
$message = $message->getMessage() . " on line " . $message->getLine() . " at file " . $message->getFile();
}
$content = (empty($method) ? '' : $method . ': ') . $message;
$message = "\033[41;37m" . $content . "\033[0m";
if (!empty($file)) {
$message .= PHP_EOL . "\03341;37m[" . $file . "\033[0m";
}
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->error($message, $context);
}
}
+3
View File
@@ -223,6 +223,7 @@ class Application extends BaseApplication
}
/**
* @throws NotFindClassException
* @throws ReflectionException
@@ -240,6 +241,8 @@ class Application extends BaseApplication
}
/**
* @param $className
* @param null $abstracts
+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);
}
}
+4 -14
View File
@@ -20,22 +20,16 @@ use Server\Abstracts\BaseProcess;
class LoggerProcess extends BaseProcess
{
/**
* @param Process $process
* @return string
*/
#[Pure] public function getProcessName(Process $process): string
{
// TODO: Implement getProcessName() method.
return get_called_class();
}
public string $name = 'logger process';
/**
* @param Process $process
* @throws ComponentException
*/
public function onHandler(Process $process): void
public function process(Process $process): void
{
// TODO: Implement onHandler() method.
$this->message($process);
@@ -49,10 +43,6 @@ class LoggerProcess extends BaseProcess
*/
public function message(Process $process)
{
if ($this->checkProcessIsStop()) {
$this->exit();
return;
}
$message = Json::decode($process->read());
if (!empty($message)) {
Kiri::writeFile($this->getDirName($message), $message[0], FILE_APPEND);
+50 -21
View File
@@ -2,9 +2,10 @@
namespace Kiri\FileListen;
use Annotation\Inject;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Logger;
use Kiri\Error\Logger;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Swoole\Coroutine;
@@ -24,12 +25,24 @@ class HotReload extends Command
public bool $isReloading = false;
public bool $isReloadingOut = false;
public ?array $dirs = [];
public int $events;
public int $int = -1;
private ?Process $process = null;
public Inotify|Scaner $driver;
#[Inject(Logger::class)]
public Logger $logger;
protected mixed $source = null;
protected mixed $pipes = [];
protected ?Coroutine\Channel $channel = null;
@@ -56,40 +69,51 @@ class HotReload extends Command
{
// TODO: Implement onHandler() method.
set_error_handler([$this, 'onErrorHandler']);
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
swoole_async_set(['enable_coroutine' => false]);
if (!extension_loaded('inotify')) {
$driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
$this->driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
} else {
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
$this->driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
}
if (Kiri::getPlatform()->isLinux()) {
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
}
$this->trigger_reload();
Coroutine::create(function () use ($driver) {
$driver->start();
});
var_dump(getmypid());
Process::signal(SIGTERM, [$this, 'onSignal']);
Process::signal(SIGKILL, [$this, 'onSignal']);
$this->driver->start();
return 0;
}
/**
* @param $data
* @throws Exception
*/
private function stop(): void
public function onSignal($data)
{
if (is_resource($this->source)) {
proc_terminate($this->source);
while (proc_get_status($this->source)['running']) {
Coroutine::sleep(1);
}
proc_close($this->source);
$this->source = null;
if (!$data) {
return;
}
$this->driver->clear();
$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);
}
while ($ret = Process::wait(true)) {
echo "PID={$ret['pid']}\n";
sleep(1);
}
}
/**
* @param $code
* @param $message
@@ -113,12 +137,17 @@ class HotReload extends Command
*/
public function trigger_reload()
{
Kiri::getDi()->get(Logger::class)->warning('change reload');
$this->stop();
Coroutine::create(function () {
$this->source = proc_open("php " . APP_PATH . "kiri.php", [], $pipes);
$this->logger->warning('change reload');
$pid = $this->process?->pid;
$process = new Process(function (Process $process) {
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);
});
$process->start();
if ($pid && Process::kill($pid, 0)) {
Process::kill($pid) && Process::wait(true);
}
$this->process = null;
$this->process = $process;
}
+10 -15
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'];
@@ -53,18 +57,17 @@ class Inotify
/**
* 开始监听
* @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)) {
@@ -72,12 +75,8 @@ class Inotify
}
//非重启类型
if (str_ends_with($ev['name'], '.php')) {
if ($this->process->int !== -1) {
return;
}
$this->process->int = @swoole_timer_after(2000, [$this, 'reload']);
$this->process->isReloading = true;
Timer::after(3000, fn()=>$this->reload());
$this->isReloading = TRUE;
}
}
}
@@ -87,16 +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;
}
@@ -151,7 +147,6 @@ class Inotify
} else if (!str_ends_with($f, '.php')) {
continue;
}
//检测文件类型
if (strstr($f, '.') == '.php') {
$wd = @inotify_add_watch($this->inotify, $path, $this->events);
+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();
+1 -1
View File
@@ -31,7 +31,7 @@ defined('TASK_PATH') or define('TASK_PATH', APP_PATH . 'app/Async/');
defined('LISTENER_PATH') or define('LISTENER_PATH', APP_PATH . 'app/Listener/');
defined('KAFKA_PATH') or define('KAFKA_PATH', APP_PATH . 'app/Kafka/');
defined('RPC_CLIENT_PATH') or define('RPC_CLIENT_PATH', APP_PATH . 'app/Client/Rpc/');
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'app/Models/');
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'app/Model/');
/**
+7
View File
@@ -220,6 +220,13 @@ class Pool extends Component
return;
}
while (static::$_connections[$name]->length() > 0) {
if (static::$_connections[$name] instanceof Channel)
{
if (!Context::inCoroutine())
{
break;
}
}
$client = static::$_connections[$name]->pop();
if ($client instanceof StopHeartbeatCheck) {
$client->stopHeartbeatCheck();
-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;
}
+4 -4
View File
@@ -30,11 +30,11 @@ class Gii
private InputInterface $input;
public string $modelPath = APP_PATH . 'app/Models/';
public string $modelNamespace = 'App\\Models\\';
public string $modelPath = APP_PATH . 'app/Model/';
public string $modelNamespace = 'App\\Model\\';
public string $controllerPath = APP_PATH . 'app/Http/Controllers/';
public string $controllerNamespace = 'App\\Controllers\\';
public string $controllerPath = APP_PATH . 'app/Http/Controller/';
public string $controllerNamespace = 'App\\Controller\\';
public static array $createSqls = [];
+4 -4
View File
@@ -24,11 +24,11 @@ abstract class GiiBase
protected InputInterface $input;
public string $modelPath = APP_PATH . 'app/Models/';
public string $modelNamespace = 'App\Models\\';
public string $modelPath = APP_PATH . 'app/Model/';
public string $modelNamespace = 'App\Model\\';
public string $controllerPath = APP_PATH . 'app/Http/Controllers/';
public string $controllerNamespace = 'App\\Controllers\\';
public string $controllerPath = APP_PATH . 'app/Http/Controller/';
public string $controllerNamespace = 'App\\Controller\\';
public ?string $module = null;
+1 -1
View File
@@ -92,7 +92,7 @@ use Kiri\Core\Json;
use Database\Connection;
use Database\Annotation\Get;
use Database\Annotation\Set;
use Annotation\Model\Relation;
use Database\Relation;
use Database\Model;
' . PHP_EOL;
}
+1 -1
View File
@@ -31,7 +31,7 @@ class GiiTask extends GiiBase
namespace App\Async;
use Server\SInterface\OnTaskInterface;
use Server\Contract\OnTaskInterface;
';
-10
View File
@@ -1,10 +0,0 @@
<?php
namespace Kiri\Process;
interface OnProcessInterface
{
public function handle();
}
-88
View File
@@ -1,88 +0,0 @@
<?php
namespace Kiri\Process;
abstract class Process implements OnProcessInterface
{
/**
* @var \Swoole\Process
*/
protected \Swoole\Process $process;
/**
* @var mixed
*/
protected mixed $redirect_stdin_and_stdout = null;
/**
* @var int
*/
protected int $pipe_type = SOCK_DGRAM;
/**
* @var bool
*/
protected bool $enable_coroutine = true;
/**
* @var string
*/
protected string $name = '';
/**
* @return \Swoole\Process
*/
public function getProcess(): \Swoole\Process
{
return $this->process;
}
/**
* @return mixed
*/
public function getRedirectStdinAndStdout(): mixed
{
return $this->redirect_stdin_and_stdout;
}
/**
* @return int
*/
public function getPipeType(): int
{
return $this->pipe_type;
}
/**
* @return bool
*/
public function isEnableCoroutine(): bool
{
return $this->enable_coroutine;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param \Swoole\Process $process
*/
public function start(\Swoole\Process $process)
{
$this->process = $process;
}
}
-52
View File
@@ -1,52 +0,0 @@
<?php
namespace Kiri\Process;
require_once 'OnProcessInterface.php';
require_once 'Process.php';
use function Co\run;
class TestProcess extends Process
{
protected string $name = 'test process';
/**
*/
public function onStart()
{
}
public function handle()
{
// TODO: Implement doWhile() method.
}
public function onShutdown()
{
// TODO: Implement onShutdown() method.
}
}
$array = [];
for ($i = 0; $i < 10; $i++) {
$class = new TestProcess();
$process = new \Swoole\Process([$class, 'start'], $class->getRedirectStdinAndStdout(),
$class->getPipeType(), $class->isEnableCoroutine());
$process->start();
array_push($array, $process);
}
run(function () use ($array) {
foreach ($array as $value) {
var_dump($value->getCallback());
}
});