modify mysql result
This commit is contained in:
@@ -59,8 +59,6 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
|
|||||||
set_env('environmental', Kiri::WORKER);
|
set_env('environmental', Kiri::WORKER);
|
||||||
$this->setProcessName(sprintf('Worker Process[%d].%d', $server->worker_pid, $workerId));
|
$this->setProcessName(sprintf('Worker Process[%d].%d', $server->worker_pid, $workerId));
|
||||||
$dispatch->dispatch(new OnWorkerStart($server, $workerId));
|
$dispatch->dispatch(new OnWorkerStart($server, $workerId));
|
||||||
|
|
||||||
$this->router->scan_build_route();
|
|
||||||
} else {
|
} else {
|
||||||
set_env('environmental', Kiri::TASK);
|
set_env('environmental', Kiri::TASK);
|
||||||
$this->setProcessName(sprintf('Tasker Process[%d].%d', $server->worker_pid, $workerId));
|
$this->setProcessName(sprintf('Tasker Process[%d].%d', $server->worker_pid, $workerId));
|
||||||
|
|||||||
+8
-2
@@ -11,10 +11,14 @@ use Swoole\Event;
|
|||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
use Swoole\Timer;
|
use Swoole\Timer;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Inotify extends BaseProcess
|
class Inotify extends BaseProcess
|
||||||
{
|
{
|
||||||
|
|
||||||
private mixed $inotify;
|
private mixed $inotify = null;
|
||||||
private mixed $events;
|
private mixed $events;
|
||||||
|
|
||||||
private array $watchFiles = [];
|
private array $watchFiles = [];
|
||||||
@@ -81,7 +85,6 @@ class Inotify extends BaseProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -100,6 +103,9 @@ class Inotify extends BaseProcess
|
|||||||
|
|
||||||
public function clear()
|
public function clear()
|
||||||
{
|
{
|
||||||
|
if (is_null($this->inotify)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Event::del($this->inotify);
|
Event::del($this->inotify);
|
||||||
Event::exit();
|
Event::exit();
|
||||||
}
|
}
|
||||||
|
|||||||
+113
-102
@@ -22,6 +22,8 @@ use Psr\Container\ContainerInterface;
|
|||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
|
use Kiri\Events\EventProvider;
|
||||||
|
use Kiri\Server\Events\OnWorkerStart;
|
||||||
|
|
||||||
|
|
||||||
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
||||||
@@ -33,10 +35,10 @@ defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
|||||||
class Server extends HttpService
|
class Server extends HttpService
|
||||||
{
|
{
|
||||||
|
|
||||||
private array $process = [];
|
private array $process = [];
|
||||||
|
|
||||||
|
|
||||||
private mixed $daemon = 0;
|
private mixed $daemon = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,132 +47,141 @@ class Server extends HttpService
|
|||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
* @param ProcessManager $processManager
|
* @param ProcessManager $processManager
|
||||||
* @param EventDispatch $eventDispatch
|
* @param EventDispatch $eventDispatch
|
||||||
|
* @param EventProvider $eventProvider
|
||||||
* @param Router $router
|
* @param Router $router
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct(public State $state,
|
public function __construct(public State $state,
|
||||||
public ServerManager $manager,
|
public ServerManager $manager,
|
||||||
public ContainerInterface $container,
|
public ContainerInterface $container,
|
||||||
public ProcessManager $processManager,
|
public ProcessManager $processManager,
|
||||||
public EventDispatch $eventDispatch,
|
public EventDispatch $eventDispatch,
|
||||||
public Router $router,
|
public EventProvider $eventProvider,
|
||||||
array $config = [])
|
public Router $router,
|
||||||
{
|
array $config = [])
|
||||||
parent::__construct($config);
|
{
|
||||||
}
|
parent::__construct($config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init(): void
|
||||||
{
|
{
|
||||||
$this->container->mapping(ResponseInterface::class, Response::class);
|
$this->container->mapping(ResponseInterface::class, Response::class);
|
||||||
$this->container->mapping(RequestInterface::class, Request::class);
|
$this->container->mapping(RequestInterface::class, Request::class);
|
||||||
|
|
||||||
$enable_coroutine = Config::get('servers.settings.enable_coroutine', false);
|
$enable_coroutine = Config::get('servers.settings.enable_coroutine', false);
|
||||||
if ($enable_coroutine != true) {
|
if (!$enable_coroutine) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Coroutine::set([
|
Coroutine::set([
|
||||||
'hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION,
|
'hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION,
|
||||||
'enable_deadlock_check' => FALSE,
|
'enable_deadlock_check' => FALSE,
|
||||||
'exit_condition' => function () {
|
'exit_condition' => function () {
|
||||||
return Coroutine::stats()['coroutine_num'] === 0;
|
return Coroutine::stats()['coroutine_num'] === 0;
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $process
|
* @param $process
|
||||||
*/
|
*/
|
||||||
public function addProcess($process)
|
public function addProcess($process)
|
||||||
{
|
{
|
||||||
$this->process[] = $process;
|
$this->process[] = $process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function start(): void
|
public function start(): void
|
||||||
{
|
{
|
||||||
$this->manager->initBaseServer(Config::get('server', [], true), $this->daemon);
|
$this->manager->initBaseServer(Config::get('server', [], true), $this->daemon);
|
||||||
|
|
||||||
$rpcService = Config::get('rpc', []);
|
$rpcService = Config::get('rpc', []);
|
||||||
if (!empty($rpcService)) {
|
if (!empty($rpcService)) {
|
||||||
$this->manager->addListener($rpcService['type'], $rpcService['host'], $rpcService['port'], $rpcService['mode'], $rpcService);
|
$this->manager->addListener($rpcService['type'], $rpcService['host'], $rpcService['port'], $rpcService['mode'], $rpcService);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $this->process[] = Inotify::class;
|
$reload = Config::get('reload.hot', false);
|
||||||
|
if ($reload !== false) {
|
||||||
|
$this->eventProvider->on(OnWorkerStart::class, [$this->router, 'scan_build_route']);
|
||||||
|
|
||||||
$processes = array_merge($this->process, Config::get('processes', []));
|
$this->process[] = Inotify::class;
|
||||||
|
} else {
|
||||||
|
$this->router->scan_build_route();
|
||||||
|
}
|
||||||
|
|
||||||
$this->processManager->batch($processes);
|
$processes = array_merge($this->process, Config::get('processes', []));
|
||||||
|
|
||||||
$this->eventDispatch->dispatch(new OnServerBeforeStart());
|
$this->processManager->batch($processes);
|
||||||
|
|
||||||
$this->manager->start();
|
$this->eventDispatch->dispatch(new OnServerBeforeStart());
|
||||||
}
|
|
||||||
|
$this->manager->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function shutdown()
|
public function shutdown(): void
|
||||||
{
|
{
|
||||||
$configs = Config::get('server', [], true);
|
$configs = Config::get('server', [], true);
|
||||||
foreach ($this->manager->sortService($configs['ports'] ?? []) as $config) {
|
foreach ($this->manager->sortService($configs['ports'] ?? []) as $config) {
|
||||||
$this->state->exit($config['port']);
|
$this->state->exit($config['port']);
|
||||||
}
|
}
|
||||||
$this->eventDispatch->dispatch(new OnShutdown());
|
$this->eventDispatch->dispatch(new OnShutdown());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function isRunner(): bool
|
public function isRunner(): bool
|
||||||
{
|
{
|
||||||
return $this->state->isRunner();
|
return $this->state->isRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $daemon
|
* @param $daemon
|
||||||
* @return Server
|
* @return Server
|
||||||
*/
|
*/
|
||||||
public function setDaemon($daemon): static
|
public function setDaemon($daemon): static
|
||||||
{
|
{
|
||||||
if (!in_array($daemon, [0, 1])) {
|
if (!in_array($daemon, [0, 1])) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
$this->daemon = $daemon;
|
$this->daemon = $daemon;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
* @return \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
||||||
*/
|
*/
|
||||||
#[Pure] public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
#[Pure] public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
||||||
{
|
{
|
||||||
return $this->manager->getServer();
|
return $this->manager->getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user