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