eee
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
namespace Kiri\Server\Abstracts;
|
namespace Kiri\Server\Abstracts;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Exception\NotFindClassException;
|
use Kiri\Exception\NotFindClassException;
|
||||||
use Kiri\Server\Config as SConfig;
|
use Kiri\Server\Config as SConfig;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Server\Handler;
|
namespace Kiri\Server\Handler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
|
||||||
use Kiri\Di\Inject\Container;
|
use Kiri\Di\Inject\Container;
|
||||||
use Kiri\Di\Context;
|
use Kiri\Di\Context;
|
||||||
use Kiri\Di\Interface\ResponseEmitterInterface;
|
use Kiri\Di\Interface\ResponseEmitterInterface;
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
namespace Kiri\Server\Handler;
|
namespace Kiri\Server\Handler;
|
||||||
|
|
||||||
|
use Kiri;
|
||||||
use Kiri\Di\Inject\Container;
|
use Kiri\Di\Inject\Container;
|
||||||
use Kiri\Error\StdoutLogger;
|
use Kiri\Error\StdoutLogger;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Kiri\Server\Abstracts\Server;
|
use Kiri\Server\Abstracts\Server;
|
||||||
@@ -36,7 +35,7 @@ class OnServer extends Server
|
|||||||
*/
|
*/
|
||||||
public function onStart(SServer $server): void
|
public function onStart(SServer $server): void
|
||||||
{
|
{
|
||||||
\Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid));
|
Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid));
|
||||||
foreach (config('server.ports') as $value) {
|
foreach (config('server.ports') as $value) {
|
||||||
$this->logger->alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']);
|
$this->logger->alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-5
@@ -45,7 +45,8 @@ class HotReload extends BaseProcess
|
|||||||
*/
|
*/
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return '[' . \config('id', 'system-service') . '].hot.load'; // TODO: Change the autogenerated stub
|
// TODO: Change the autogenerated stub
|
||||||
|
return '[' . \config('id', 'system-service') . '].hot.load';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ class HotReload extends BaseProcess
|
|||||||
$this->watch(rtrim($dir, '/'));
|
$this->watch(rtrim($dir, '/'));
|
||||||
}
|
}
|
||||||
Event::add($this->inotify, fn() => $this->check());
|
Event::add($this->inotify, fn() => $this->check());
|
||||||
Event::cycle(fn() => function() {
|
Event::cycle(fn() => function () {
|
||||||
Event::dispatch();
|
Event::dispatch();
|
||||||
}, true);
|
}, true);
|
||||||
Event::wait();
|
Event::wait();
|
||||||
@@ -204,7 +205,7 @@ class HotReload extends BaseProcess
|
|||||||
*/
|
*/
|
||||||
private function checkFile($value, $isReload): bool
|
private function checkFile($value, $isReload): bool
|
||||||
{
|
{
|
||||||
$md5 = md5($value);
|
$md5 = md5($value);
|
||||||
$mTime = filectime($value);
|
$mTime = filectime($value);
|
||||||
if (!isset($this->md5Map[$md5])) {
|
if (!isset($this->md5Map[$md5])) {
|
||||||
if ($isReload) {
|
if ($isReload) {
|
||||||
@@ -341,7 +342,7 @@ class HotReload extends BaseProcess
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$wd = @inotify_add_watch($this->inotify, $dir, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE);
|
$wd = @inotify_add_watch($this->inotify, $dir, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE);
|
||||||
$this->watchFiles[$dir] = $wd;
|
$this->watchFiles[$dir] = $wd;
|
||||||
|
|
||||||
$files = scandir($dir);
|
$files = scandir($dir);
|
||||||
@@ -358,7 +359,7 @@ class HotReload extends BaseProcess
|
|||||||
|
|
||||||
//检测文件类型
|
//检测文件类型
|
||||||
if (strstr($f, '.') == '.php') {
|
if (strstr($f, '.') == '.php') {
|
||||||
$wd = @inotify_add_watch($this->inotify, $path, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE);
|
$wd = @inotify_add_watch($this->inotify, $path, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE);
|
||||||
$this->watchFiles[$path] = $wd;
|
$this->watchFiles[$path] = $wd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use function config;
|
||||||
|
|
||||||
defined('ROUTER_TYPE_HTTP') or define('ROUTER_TYPE_HTTP', 'http');
|
defined('ROUTER_TYPE_HTTP') or define('ROUTER_TYPE_HTTP', 'http');
|
||||||
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
||||||
@@ -99,7 +100,7 @@ class ServerCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected function stop(): int
|
protected function stop(): int
|
||||||
{
|
{
|
||||||
$configs = \config('server', []);
|
$configs = config('server', []);
|
||||||
$instances = $this->manager->sortService($configs['ports'] ?? []);
|
$instances = $this->manager->sortService($configs['ports'] ?? []);
|
||||||
foreach ($instances as $config) {
|
foreach ($instances as $config) {
|
||||||
$this->state->exit($config->port);
|
$this->state->exit($config->port);
|
||||||
@@ -117,13 +118,13 @@ class ServerCommand extends Command
|
|||||||
protected function start(InputInterface $input): int
|
protected function start(InputInterface $input): int
|
||||||
{
|
{
|
||||||
$daemon = (int)$input->getOption('daemon');
|
$daemon = (int)$input->getOption('daemon');
|
||||||
if (\config('reload.hot', false) === true) {
|
if (config('reload.hot', false) === true) {
|
||||||
$this->manager->addProcess(HotReload::class);
|
$this->manager->addProcess(HotReload::class);
|
||||||
} else {
|
} else {
|
||||||
$this->router->scan_build_route();
|
$this->router->scan_build_route();
|
||||||
}
|
}
|
||||||
$this->manager->addProcess(config('processes', []));
|
$this->manager->addProcess(config('processes', []));
|
||||||
$this->manager->initCoreServers(\config('server', []), $daemon);
|
$this->manager->initCoreServers(config('server', []), $daemon);
|
||||||
$this->manager->start();
|
$this->manager->start();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use Kiri\Abstracts\Providers;
|
|||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Kiri;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DatabasesProviders
|
* Class DatabasesProviders
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use Exception;
|
|||||||
use Kiri\Abstracts\Component;
|
use Kiri\Abstracts\Component;
|
||||||
use Kiri\Server\Abstracts\TraitServer;
|
use Kiri\Server\Abstracts\TraitServer;
|
||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
|
use function config;
|
||||||
|
|
||||||
class State extends Component
|
class State extends Component
|
||||||
{
|
{
|
||||||
@@ -21,7 +22,7 @@ class State extends Component
|
|||||||
*/
|
*/
|
||||||
public function init(): void
|
public function init(): void
|
||||||
{
|
{
|
||||||
$this->servers = \config('server.ports');
|
$this->servers = config('server.ports');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -3,6 +3,7 @@
|
|||||||
namespace Kiri\Server\Task;
|
namespace Kiri\Server\Task;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Server\Constant;
|
use Kiri\Server\Constant;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
@@ -50,7 +51,7 @@ class Task
|
|||||||
* @param int $src_worker_id
|
* @param int $src_worker_id
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException|Exception
|
||||||
*/
|
*/
|
||||||
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed
|
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user