Compare commits

...

45 Commits

Author SHA1 Message Date
as2252258 829c063700 Revert "改名"
This reverts commit fdf58326
2022-01-14 14:54:13 +08:00
as2252258 eaf251ac53 Revert "改名"
This reverts commit fdf58326
2022-01-14 14:45:03 +08:00
as2252258 776cc80495 Revert "改名"
This reverts commit fdf58326
2022-01-14 14:43:04 +08:00
as2252258 103cc96103 Revert "改名"
This reverts commit fdf58326
2022-01-14 14:19:52 +08:00
as2252258 f2da99efce Revert "改名"
This reverts commit fdf58326
2022-01-14 14:18:29 +08:00
as2252258 49d0ba7b3c Revert "改名"
This reverts commit fdf58326
2022-01-14 11:43:02 +08:00
as2252258 a6ed92206e Revert "改名"
This reverts commit fdf58326
2022-01-14 11:41:30 +08:00
as2252258 bb9b9dbcd2 Revert "改名"
This reverts commit fdf58326
2022-01-14 11:40:20 +08:00
as2252258 9782147a47 Revert "改名"
This reverts commit fdf58326
2022-01-14 11:39:52 +08:00
as2252258 7598bdbd63 Revert "改名"
This reverts commit fdf58326
2022-01-14 11:38:28 +08:00
as2252258 a569bd6897 Revert "改名"
This reverts commit fdf58326
2022-01-14 11:29:16 +08:00
as2252258 ffeef3ff4b Revert "改名"
This reverts commit fdf58326
2022-01-13 18:48:13 +08:00
as2252258 7f6a0c01e0 Revert "改名"
This reverts commit fdf58326
2022-01-13 18:41:16 +08:00
as2252258 32f9ebc2a2 Revert "改名"
This reverts commit fdf58326
2022-01-13 18:39:39 +08:00
as2252258 f35ffe6ff1 Revert "改名"
This reverts commit fdf58326
2022-01-13 18:33:04 +08:00
as2252258 9a76ee0184 Revert "改名"
This reverts commit fdf58326
2022-01-13 10:15:04 +08:00
as2252258 249f9b1c6f Revert "改名"
This reverts commit fdf58326
2022-01-12 18:52:13 +08:00
as2252258 1df2d43b8b Revert "改名"
This reverts commit fdf58326
2022-01-12 18:50:48 +08:00
as2252258 2daac841a3 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:49:57 +08:00
as2252258 28cd946219 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:30:28 +08:00
as2252258 70015f7ab8 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:29:49 +08:00
as2252258 a467056c86 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:28:51 +08:00
as2252258 a2a3f0fc40 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:27:49 +08:00
as2252258 cfbebeb951 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:26:54 +08:00
as2252258 94851c3f51 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:22:53 +08:00
as2252258 1896dc90b4 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:14:15 +08:00
as2252258 6168adb401 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:12:56 +08:00
as2252258 5e742e7196 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:09:49 +08:00
as2252258 4605fc9162 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:08:28 +08:00
as2252258 54f19fb058 Revert "改名"
This reverts commit fdf58326
2022-01-12 18:05:49 +08:00
as2252258 a9165b601a Revert "改名"
This reverts commit fdf58326
2022-01-12 18:03:09 +08:00
as2252258 5b35c4de4a Revert "改名"
This reverts commit fdf58326
2022-01-12 18:02:45 +08:00
as2252258 8b6aff5c7b Revert "改名"
This reverts commit fdf58326
2022-01-12 18:01:55 +08:00
as2252258 1d3b45e2c3 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:58:01 +08:00
as2252258 f2ad97c7f0 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:55:25 +08:00
as2252258 19b3f0f1e9 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:54:18 +08:00
as2252258 ebd643772d Revert "改名"
This reverts commit fdf58326
2022-01-12 17:53:27 +08:00
as2252258 08d9551245 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:52:18 +08:00
as2252258 59eec80939 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:46:16 +08:00
as2252258 241385b575 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:39:11 +08:00
as2252258 73ce2b8a50 Revert "改名"
This reverts commit fdf58326
2022-01-12 17:38:25 +08:00
as2252258 6f80b2fe6a Revert "改名"
This reverts commit fdf58326
2022-01-12 17:17:47 +08:00
as2252258 8955891c2f Revert "改名"
This reverts commit fdf58326
2022-01-12 16:01:55 +08:00
as2252258 035138a779 Revert "改名"
This reverts commit fdf58326
2022-01-12 16:00:11 +08:00
as2252258 c6e6c8d68d Revert "改名"
This reverts commit fdf58326
2022-01-12 15:47:28 +08:00
9 changed files with 53 additions and 35 deletions
+4 -5
View File
@@ -1241,17 +1241,16 @@ if (!function_exists('error_trigger_format')) {
*/ */
function error_trigger_format(\Throwable|\Error $throwable): string function error_trigger_format(\Throwable|\Error $throwable): string
{ {
$message = 'Throwable: ' . $throwable->getMessage() . "\r\n" . ' $message = "Throwable: " . $throwable->getMessage() . "\n" . ' ' . $throwable->getFile() . " at line " . $throwable->getLine() . "\n";
' . $throwable->getFile() . " at line" . $throwable->getLine();
$message .= 'trance' . "\r\n"; $message .= "trance\n";
foreach ($throwable->getTrace() as $value) { foreach ($throwable->getTrace() as $value) {
if (!isset($value['file'])) { if (!isset($value['file'])) {
continue; continue;
} }
$message .= $value['file'] . '->' . $value['line'] . '(' . $value['class'] . '::' . $value['function'] . ')'; $message .= $value['file'] . " -> " . $value['line'] . "(" . (isset($value['class']) ? $value['class'] . '::' : '') . ($value['function'] ?? 'Closure') . ")\n";
} }
return $message; return "\033[41;37m" . $message . "\033[0m";
} }
} }
+4 -1
View File
@@ -6,8 +6,8 @@ namespace Kiri\Annotation;
use DirectoryIterator; use DirectoryIterator;
use Exception; use Exception;
use Kiri\Abstracts\Component;
use Kiri; use Kiri;
use Kiri\Abstracts\Component;
use ReflectionClass; use ReflectionClass;
use ReflectionException; use ReflectionException;
use Throwable; use Throwable;
@@ -84,6 +84,9 @@ class Loader extends Component
public function _scanDir(DirectoryIterator $paths, $namespace, array $exclude = []) public function _scanDir(DirectoryIterator $paths, $namespace, array $exclude = [])
{ {
foreach ($paths as $path) { foreach ($paths as $path) {
if (function_exists('opcache_invalidate')) {
opcache_invalidate($path->getRealPath(), true);
}
if ($path->isDot() || str_starts_with($path->getFilename(), '.')) { if ($path->isDot() || str_starts_with($path->getFilename(), '.')) {
continue; continue;
} }
+3 -3
View File
@@ -14,7 +14,8 @@ use Database\Connection;
use Exception; use Exception;
use Kiri\Message\Handler\Router; use Kiri\Message\Handler\Router;
use Kafka\KafkaProvider; use Kafka\KafkaProvider;
use Kiri\{Async, Kiri}; use Kiri\Async;
use Kiri;
use Kiri\Annotation\Annotation as SAnnotation; use Kiri\Annotation\Annotation as SAnnotation;
use Kiri\Cache\Redis; use Kiri\Cache\Redis;
use Kiri\Di\LocalService; use Kiri\Di\LocalService;
@@ -369,7 +370,7 @@ abstract class BaseApplication extends Component
*/ */
public function getServer(): Server public function getServer(): Server
{ {
return $this->get('server'); return Kiri::getDi()->get(Server::class);
} }
@@ -443,7 +444,6 @@ abstract class BaseApplication extends Component
'logger' => ['class' => Logger::class], 'logger' => ['class' => Logger::class],
'Annotation' => ['class' => SAnnotation::class], 'Annotation' => ['class' => SAnnotation::class],
'databases' => ['class' => Connection::class], 'databases' => ['class' => Connection::class],
'jwt' => ['class' => Jwt::class],
'async' => ['class' => Async::class], 'async' => ['class' => Async::class],
'kafka-container' => ['class' => KafkaProvider::class], 'kafka-container' => ['class' => KafkaProvider::class],
]); ]);
+1 -1
View File
@@ -70,7 +70,7 @@ class Component implements Configure
*/ */
protected function getEventDispatch(): EventDispatch protected function getEventDispatch(): EventDispatch
{ {
return Kiri::getDi()->get(EventDispatch::class); return $this->getContainer()->get(EventDispatch::class);
} }
/** /**
+25 -4
View File
@@ -4,9 +4,11 @@ namespace Kiri\Cache\Base;
use Exception; use Exception;
use Kiri\Abstracts\Logger; use Kiri\Abstracts\Logger;
use Kiri\Events\EventProvider;
use Kiri\Exception\RedisConnectException; use Kiri\Exception\RedisConnectException;
use Kiri; use Kiri;
use Kiri\Pool\StopHeartbeatCheck; use Kiri\Pool\StopHeartbeatCheck;
use Kiri\Server\Events\OnWorkerExit;
use RedisException; use RedisException;
use Swoole\Timer; use Swoole\Timer;
@@ -43,6 +45,9 @@ class Redis implements StopHeartbeatCheck
private int $_last = 0; private int $_last = 0;
private EventProvider $eventProvider;
/** /**
* @param array $config * @param array $config
*/ */
@@ -62,6 +67,21 @@ class Redis implements StopHeartbeatCheck
public function init() public function init()
{ {
$this->heartbeat_check(); $this->heartbeat_check();
$this->eventProvider = Kiri::getDi()->get(EventProvider::class);
$this->eventProvider->on(OnWorkerExit::class, [$this, 'onWorkerExit']);
}
/**
* @param Kiri\Server\Events\OnWorkerExit $exit
* @return void
*/
public function onWorkerExit(OnWorkerExit $exit)
{
$this->stopHeartbeatCheck();
} }
@@ -70,9 +90,7 @@ class Redis implements StopHeartbeatCheck
*/ */
public function heartbeat_check(): void public function heartbeat_check(): void
{ {
if (env('state', 'start') == 'exit') {
return;
}
if ($this->_timer === -1) { if ($this->_timer === -1) {
$this->_timer = Timer::tick(1000, fn() => $this->waite()); $this->_timer = Timer::tick(1000, fn() => $this->waite());
} }
@@ -85,12 +103,15 @@ class Redis implements StopHeartbeatCheck
private function waite(): void private function waite(): void
{ {
try { try {
if (env('state', 'start') == 'exit') { if ($this->_timer === -1) {
Kiri::getDi()->get(Logger::class)->critical('timer end'); Kiri::getDi()->get(Logger::class)->critical('timer end');
$this->stopHeartbeatCheck(); $this->stopHeartbeatCheck();
} }
if (time() - $this->_last > intval($this->pool['tick'] ?? 60)) { if (time() - $this->_last > intval($this->pool['tick'] ?? 60)) {
$this->stopHeartbeatCheck(); $this->stopHeartbeatCheck();
$this->eventProvider->off(OnWorkerExit::class, [$this, 'stopHeartbeatCheck']);
$this->pdo = null; $this->pdo = null;
} }
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
+2 -3
View File
@@ -204,21 +204,20 @@ class HotReload extends Command
public function trigger_reload(string $path = '') public function trigger_reload(string $path = '')
{ {
$this->logger->warning('change reload'); $this->logger->warning('change reload');
var_dump($path);
if (!empty($path) && str_starts_with($path, CONTROLLER_PATH)) { if (!empty($path) && str_starts_with($path, CONTROLLER_PATH)) {
$pid = file_get_contents(storage('.swoole.pid')); $pid = file_get_contents(storage('.swoole.pid'));
if (!empty($pid) && Process::kill($pid, 0)) { if (!empty($pid) && Process::kill($pid, 0)) {
Process::kill($pid, SIGUSR1); Process::kill($pid, SIGUSR1);
} }
} else { } else {
if ($this->int == 1) {
return;
}
$this->int = 1; $this->int = 1;
$this->stopServer(); $this->stopServer();
$this->process = new Process(function (Process $process) { $this->process = new Process(function (Process $process) {
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "start"]); $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "start"]);
}); });
$this->process->start(); $this->process->start();
$this->int = -1;
} }
} }
+8 -1
View File
@@ -54,6 +54,7 @@ class Inotify
if (!is_dir($dir)) continue; if (!is_dir($dir)) continue;
$this->watch($dir); $this->watch($dir);
} }
$this->process->int = -1;
Event::add($this->inotify, [$this, 'check']); Event::add($this->inotify, [$this, 'check']);
Event::wait(); Event::wait();
} }
@@ -84,8 +85,13 @@ class Inotify
if (!in_array($ev['mask'], $LISTEN_TYPE)) { if (!in_array($ev['mask'], $LISTEN_TYPE)) {
continue; continue;
} }
var_dump($ev);
//非重启类型 //非重启类型
if (str_ends_with($ev['name'], '.php')) { if (str_ends_with($ev['name'], '.php')) {
Timer::after(3000, fn() => $this->reload($ev['name'])); Timer::after(3000, fn() => $this->reload($ev['name']));
$this->isReloading = TRUE; $this->isReloading = TRUE;
} }
@@ -98,11 +104,12 @@ class Inotify
public function reload($path) public function reload($path)
{ {
$this->process->trigger_reload($path); $this->process->trigger_reload($path);
$this->process->int = -1;
$this->clearWatch(); $this->clearWatch();
foreach ($this->dirs as $root) { foreach ($this->dirs as $root) {
$this->watch($root); $this->watch($root);
} }
$this->process->int = -1;
$this->isReloading = FALSE; $this->isReloading = FALSE;
} }
+4 -4
View File
@@ -3,7 +3,6 @@
namespace Kiri\FileListen; namespace Kiri\FileListen;
use Exception; use Exception;
use Swoole\Timer;
class Scaner class Scaner
{ {
@@ -68,8 +67,11 @@ class Scaner
} }
if (is_file($value)) { if (is_file($value)) {
if ($this->checkFile($value, $isReload)) { if ($this->checkFile($value, $isReload)) {
Timer::after(2000, fn() => $this->timerReload());
$this->isReloading = TRUE; $this->isReloading = TRUE;
sleep(2);
$this->timerReload($value);
break; break;
} }
} }
@@ -110,8 +112,6 @@ class Scaner
{ {
$this->isReloading = TRUE; $this->isReloading = TRUE;
if (str_contains($path, CONTROLLER_PATH))
$this->process->trigger_reload($path); $this->process->trigger_reload($path);
$this->loadDirs(); $this->loadDirs();
+2 -13
View File
@@ -4,20 +4,17 @@ namespace Kiri\Websocket;
use Exception; use Exception;
use Kiri\Message\Handler\DataGrip; use Kiri\Message\Handler\DataGrip;
use Kiri\Message\Handler\Router;
use Kiri\Abstracts\AbstractServer; use Kiri\Abstracts\AbstractServer;
use Kiri\Annotation\Inject; use Kiri\Message\Handler\RouterCollector;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Kiri\Server\Contract\OnCloseInterface; use Kiri\Server\Contract\OnCloseInterface;
use Kiri\Server\Contract\OnHandshakeInterface; use Kiri\Server\Contract\OnHandshakeInterface;
use Kiri\Server\Contract\OnMessageInterface; use Kiri\Server\Contract\OnMessageInterface;
use Kiri\Server\Contract\OnOpenInterface; use Kiri\Server\Contract\OnOpenInterface;
use Kiri\Server\SwooleServerInterface;
use Swoole\Http\Request; use Swoole\Http\Request;
use Swoole\Http\Response; use Swoole\Http\Response;
use Swoole\WebSocket\Frame; use Swoole\WebSocket\Frame;
use Swoole\WebSocket\Server as WebSocketServer;
/** /**
@@ -26,7 +23,7 @@ use Swoole\WebSocket\Server as WebSocketServer;
class Server extends AbstractServer class Server extends AbstractServer
{ {
public Router $router; public RouterCollector $router;
const SHA1_KEY = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; const SHA1_KEY = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
@@ -35,14 +32,6 @@ class Server extends AbstractServer
public mixed $callback = null; public mixed $callback = null;
/**
* @var WebSocketInterface
*/
#[Inject(WebSocketInterface::class)]
public WebSocketInterface $server;
/** /**
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface