2022-03-15 18:05:33 +08:00
|
|
|
|
<?php
|
2021-03-29 15:34:24 +08:00
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
/** @noinspection PhpComposerExtensionStubsInspection */
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2021-03-29 15:34:24 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ZM\Event\SwooleEvent;
|
|
|
|
|
|
|
|
|
|
|
|
use Error;
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
use PDO;
|
|
|
|
|
|
use ReflectionException;
|
|
|
|
|
|
use Swoole\Coroutine;
|
|
|
|
|
|
use Swoole\Database\PDOConfig;
|
|
|
|
|
|
use Swoole\Process;
|
2022-04-03 01:47:38 +08:00
|
|
|
|
use Swoole\WebSocket\Server;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
use ZM\Annotation\AnnotationParser;
|
2021-09-11 11:59:02 +08:00
|
|
|
|
use ZM\Annotation\Swoole\OnMessageEvent;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
use ZM\Annotation\Swoole\OnStart;
|
|
|
|
|
|
use ZM\Annotation\Swoole\SwooleHandler;
|
|
|
|
|
|
use ZM\Config\ZMConfig;
|
|
|
|
|
|
use ZM\Console\Console;
|
2022-04-10 00:58:07 +08:00
|
|
|
|
use ZM\Container\WorkerContainer;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
use ZM\Context\Context;
|
|
|
|
|
|
use ZM\Context\ContextInterface;
|
|
|
|
|
|
use ZM\DB\DB;
|
|
|
|
|
|
use ZM\Event\EventDispatcher;
|
|
|
|
|
|
use ZM\Event\EventManager;
|
|
|
|
|
|
use ZM\Event\SwooleEvent;
|
|
|
|
|
|
use ZM\Exception\DbException;
|
2021-09-01 14:14:00 +08:00
|
|
|
|
use ZM\Exception\ZMKnownException;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
use ZM\Framework;
|
|
|
|
|
|
use ZM\Module\QQBot;
|
2021-07-09 01:38:30 +08:00
|
|
|
|
use ZM\MySQL\MySQLPool;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
use ZM\Store\LightCacheInside;
|
|
|
|
|
|
use ZM\Store\MySQL\SqlPoolStorage;
|
|
|
|
|
|
use ZM\Store\Redis\ZMRedisPool;
|
|
|
|
|
|
use ZM\Utils\DataProvider;
|
2022-03-26 14:51:57 +08:00
|
|
|
|
use ZM\Utils\Manager\CronManager;
|
2021-09-01 14:14:00 +08:00
|
|
|
|
use ZM\Utils\Manager\ModuleManager;
|
2021-06-16 00:17:30 +08:00
|
|
|
|
use ZM\Utils\SignalListener;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Class OnWorkerStart
|
|
|
|
|
|
* @SwooleHandler("WorkerStart")
|
|
|
|
|
|
*/
|
|
|
|
|
|
class OnWorkerStart implements SwooleEvent
|
|
|
|
|
|
{
|
2022-04-03 01:22:19 +08:00
|
|
|
|
public function onCall(Server $server, int $worker_id)
|
2022-03-13 22:46:22 +08:00
|
|
|
|
{
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::debug('Calling onWorkerStart event(1)');
|
|
|
|
|
|
if (!Framework::$argv['disable-safe-exit']) {
|
2021-06-16 00:17:30 +08:00
|
|
|
|
SignalListener::signalWorker($server, $worker_id);
|
2021-05-08 10:02:41 +08:00
|
|
|
|
}
|
2021-03-29 15:34:24 +08:00
|
|
|
|
unset(Context::$context[Coroutine::getCid()]);
|
2022-04-10 00:58:07 +08:00
|
|
|
|
|
2022-04-11 23:31:49 +08:00
|
|
|
|
$this->registerWorkerContainerBindings($server);
|
2022-04-10 00:58:07 +08:00
|
|
|
|
|
2021-03-29 15:34:24 +08:00
|
|
|
|
if ($server->taskworker === false) {
|
2022-03-13 22:46:22 +08:00
|
|
|
|
Framework::saveProcessState(ZM_PROCESS_WORKER, $server->worker_pid, ['worker_id' => $worker_id]);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
zm_atomic('_#worker_' . $worker_id)->set($server->worker_pid);
|
|
|
|
|
|
if (LightCacheInside::get('wait_api', 'wait_api') !== null) {
|
|
|
|
|
|
LightCacheInside::unset('wait_api', 'wait_api');
|
2021-03-29 15:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
register_shutdown_function(function () use ($server) {
|
|
|
|
|
|
$error = error_get_last();
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (($error['type'] ?? 0) != 0) {
|
|
|
|
|
|
Console::error(zm_internal_errcode('E00027') . 'Internal fatal error: ' . $error['message'] . ' at ' . $error['file'] . "({$error['line']})");
|
2021-06-16 00:17:30 +08:00
|
|
|
|
zm_dump($error);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
} elseif (!isset($error['type'])) {
|
2021-07-09 01:38:30 +08:00
|
|
|
|
return;
|
2021-03-29 15:34:24 +08:00
|
|
|
|
}
|
2022-03-20 16:23:07 +08:00
|
|
|
|
// DataProvider::saveBuffer();
|
2022-04-03 01:47:38 +08:00
|
|
|
|
$server->shutdown();
|
2021-03-29 15:34:24 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2021-06-16 00:17:30 +08:00
|
|
|
|
Console::verbose("Worker #{$server->worker_id} starting");
|
2021-03-29 15:34:24 +08:00
|
|
|
|
Framework::$server = $server;
|
2022-03-20 16:23:07 +08:00
|
|
|
|
// ZMBuf::resetCache(); //清空变量缓存
|
|
|
|
|
|
// ZMBuf::set("wait_start", []); //添加队列,在workerStart运行完成前先让其他协程等待执行
|
2021-03-29 15:34:24 +08:00
|
|
|
|
|
2022-03-20 16:23:07 +08:00
|
|
|
|
// TODO: 单独抽出来MySQL和Redis连接池
|
2021-07-09 01:38:30 +08:00
|
|
|
|
$this->initMySQLPool();
|
2021-03-29 15:34:24 +08:00
|
|
|
|
|
|
|
|
|
|
// 开箱即用的Redis
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$redis = ZMConfig::get('global', 'redis_config');
|
|
|
|
|
|
if ($redis !== null && $redis['host'] != '') {
|
|
|
|
|
|
if (!extension_loaded('redis')) {
|
|
|
|
|
|
Console::error(zm_internal_errcode('E00029') . "Can not find redis extension.\n");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ZMRedisPool::init($redis);
|
|
|
|
|
|
}
|
2021-03-29 15:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-20 16:23:07 +08:00
|
|
|
|
$this->loadAnnotations(); // 加载composer资源、phar外置包、注解解析注册等
|
2022-03-26 14:51:57 +08:00
|
|
|
|
CronManager::initCronTasks(); // 初始化定时任务
|
2022-03-20 16:23:07 +08:00
|
|
|
|
EventManager::registerTimerTick(); // 启动计时器
|
2022-03-26 14:51:57 +08:00
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
set_coroutine_params(['server' => $server, 'worker_id' => $worker_id]);
|
2021-03-29 15:34:24 +08:00
|
|
|
|
$dispatcher = new EventDispatcher(OnStart::class);
|
|
|
|
|
|
$dispatcher->setRuleFunction(function ($v) {
|
|
|
|
|
|
return server()->worker_id === $v->worker_id || $v->worker_id === -1;
|
|
|
|
|
|
});
|
|
|
|
|
|
$dispatcher->dispatchEvents($server, $worker_id);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if ($dispatcher->status === EventDispatcher::STATUS_NORMAL) {
|
|
|
|
|
|
Console::debug('@OnStart 执行完毕');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Console::warning('@OnStart 执行异常!');
|
|
|
|
|
|
}
|
|
|
|
|
|
Console::success('Worker #' . $worker_id . ' started');
|
2021-03-29 15:34:24 +08:00
|
|
|
|
} catch (Exception $e) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::error('Worker加载出错!停止服务!');
|
|
|
|
|
|
Console::error(zm_internal_errcode('E00030') . $e->getMessage() . "\n" . $e->getTraceAsString());
|
2021-03-29 15:34:24 +08:00
|
|
|
|
Process::kill($server->master_pid, SIGTERM);
|
|
|
|
|
|
return;
|
|
|
|
|
|
} catch (Error $e) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::error(zm_internal_errcode('E00030') . 'PHP Error: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
|
|
|
|
|
|
Console::error('Maybe it caused by your own code if in your own Module directory.');
|
2021-03-29 15:34:24 +08:00
|
|
|
|
Console::log($e->getTraceAsString(), 'gray');
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (!Framework::$argv['watch']) { // 在热更新模式下不能退出
|
2022-03-13 22:46:22 +08:00
|
|
|
|
Process::kill($server->master_pid, SIGTERM);
|
|
|
|
|
|
}
|
2021-03-29 15:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 这里是TaskWorker初始化的内容部分
|
2022-03-13 22:46:22 +08:00
|
|
|
|
Framework::saveProcessState(ZM_PROCESS_TASKWORKER, $server->worker_pid, ['worker_id' => $worker_id]);
|
2021-03-29 15:34:24 +08:00
|
|
|
|
try {
|
|
|
|
|
|
Framework::$server = $server;
|
|
|
|
|
|
$this->loadAnnotations();
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::success('TaskWorker #' . $server->worker_id . ' started');
|
2021-03-29 15:34:24 +08:00
|
|
|
|
} catch (Exception $e) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::error('Worker加载出错!停止服务!');
|
|
|
|
|
|
Console::error(zm_internal_errcode('E00030') . $e->getMessage() . "\n" . $e->getTraceAsString());
|
2021-03-29 15:34:24 +08:00
|
|
|
|
Process::kill($server->master_pid, SIGTERM);
|
|
|
|
|
|
return;
|
|
|
|
|
|
} catch (Error $e) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::error(zm_internal_errcode('E00030') . 'PHP Error: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
|
|
|
|
|
|
Console::error('Maybe it caused by your own code if in your own Module directory.');
|
2021-03-29 15:34:24 +08:00
|
|
|
|
Console::log($e->getTraceAsString(), 'gray');
|
|
|
|
|
|
Process::kill($server->master_pid, SIGTERM);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @throws ReflectionException
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
2022-03-13 22:46:22 +08:00
|
|
|
|
private function loadAnnotations()
|
|
|
|
|
|
{
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (Framework::$instant_mode) {
|
|
|
|
|
|
goto skip;
|
|
|
|
|
|
}
|
2022-03-20 16:23:07 +08:00
|
|
|
|
// 加载各个模块的注解类,以及反射
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::debug('Mapping annotations');
|
2021-03-29 15:34:24 +08:00
|
|
|
|
$parser = new AnnotationParser();
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
|
|
|
|
|
|
$merge = array_merge($composer['autoload']['psr-4'] ?? [], $composer['autoload-dev']['psr-4'] ?? []);
|
2022-03-20 16:51:48 +08:00
|
|
|
|
$exclude_annotations = array_merge($composer['extra']['exclude_annotate'] ?? [], $composer['extra']['zm']['exclude-annotation-path'] ?? []);
|
2022-03-13 22:46:22 +08:00
|
|
|
|
foreach ($merge as $k => $v) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (is_dir(DataProvider::getSourceRootDir() . '/' . $v)) {
|
2022-03-29 02:09:00 +08:00
|
|
|
|
if (in_array($v, $exclude_annotations)) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (trim($k, '\\') == 'ZM') {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
$parser->addRegisterPath(DataProvider::getSourceRootDir() . '/' . $v . '/', trim($k, '\\'));
|
2021-03-29 15:34:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
|
// 检查是否允许热加载phar模块,允许的话将遍历phar内的文件
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$plugin_enable_hotload = ZMConfig::get('global', 'module_loader')['enable_hotload'] ?? false;
|
2021-09-01 14:14:00 +08:00
|
|
|
|
if ($plugin_enable_hotload) {
|
|
|
|
|
|
$list = ModuleManager::getPackedModules();
|
2022-03-13 22:46:22 +08:00
|
|
|
|
foreach ($list as $k => $v) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (\server()->worker_id === 0) {
|
|
|
|
|
|
Console::info('Loading packed module: ' . $k);
|
|
|
|
|
|
}
|
|
|
|
|
|
require_once $v['phar-path'];
|
|
|
|
|
|
$func = 'loader' . $v['generated-id'];
|
2021-09-01 14:14:00 +08:00
|
|
|
|
$func();
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$parser->addRegisterPath('phar://' . $v['phar-path'] . '/' . $v['module-root-path'], $v['namespace']);
|
2021-09-01 14:14:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-21 01:24:07 +08:00
|
|
|
|
// 检查所有的Composer模块,并加载注解
|
|
|
|
|
|
$list = ModuleManager::getComposerModules();
|
|
|
|
|
|
foreach ($list as $k => $v) {
|
|
|
|
|
|
if (\server()->worker_id === 0) {
|
|
|
|
|
|
Console::info('Loading composer module: ' . $k);
|
|
|
|
|
|
}
|
|
|
|
|
|
$parser->addRegisterPath($v['module-path'], $v['namespace']);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
|
$parser->registerMods();
|
2022-03-20 16:23:07 +08:00
|
|
|
|
EventManager::loadEventByParser($parser); // 加载事件
|
2021-09-11 11:59:02 +08:00
|
|
|
|
|
2021-11-02 16:01:24 +08:00
|
|
|
|
skip:
|
2022-03-20 16:23:07 +08:00
|
|
|
|
// 加载自定义的全局函数
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::debug('Loading context class...');
|
|
|
|
|
|
$context_class = ZMConfig::get('global', 'context_class');
|
2021-11-02 16:01:24 +08:00
|
|
|
|
if (!is_a($context_class, ContextInterface::class, true)) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
throw new ZMKnownException('E00032', 'Context class must implemented from ContextInterface!');
|
2021-11-02 16:01:24 +08:00
|
|
|
|
}
|
2022-03-20 16:23:07 +08:00
|
|
|
|
// 加载插件
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$obb_onebot = ZMConfig::get('global', 'onebot') ??
|
|
|
|
|
|
ZMConfig::get('global', 'modules')['onebot'] ??
|
|
|
|
|
|
['status' => true, 'single_bot_mode' => false, 'message_level' => 99999];
|
|
|
|
|
|
if ($obb_onebot['status']) {
|
|
|
|
|
|
Console::debug('OneBot support enabled, listening OneBot event(3).');
|
2021-09-11 11:59:02 +08:00
|
|
|
|
$obj = new OnMessageEvent();
|
2022-03-27 21:34:49 +08:00
|
|
|
|
$obj->connect_type = 'qq';
|
2021-09-11 11:59:02 +08:00
|
|
|
|
$obj->class = QQBot::class;
|
|
|
|
|
|
$obj->method = 'handleByEvent';
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$obj->level = $obb_onebot['message_level'] ?? 99;
|
2021-09-11 11:59:02 +08:00
|
|
|
|
EventManager::addEvent(OnMessageEvent::class, $obj);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if ($obb_onebot['single_bot_mode']) {
|
|
|
|
|
|
LightCacheInside::set('connect', 'conn_fd', -1);
|
2021-09-11 11:59:02 +08:00
|
|
|
|
} else {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
LightCacheInside::set('connect', 'conn_fd', -2);
|
2021-09-11 11:59:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-29 15:34:24 +08:00
|
|
|
|
}
|
2021-07-09 01:38:30 +08:00
|
|
|
|
|
2022-03-13 22:46:22 +08:00
|
|
|
|
private function initMySQLPool()
|
|
|
|
|
|
{
|
2021-07-09 01:38:30 +08:00
|
|
|
|
if (SqlPoolStorage::$sql_pool !== null) {
|
|
|
|
|
|
SqlPoolStorage::$sql_pool->close();
|
|
|
|
|
|
SqlPoolStorage::$sql_pool = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
$real_conf = [];
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (isset(ZMConfig::get('global', 'sql_config')['sql_host'])) {
|
|
|
|
|
|
if (ZMConfig::get('global', 'sql_config')['sql_host'] != '') {
|
2021-07-09 01:38:30 +08:00
|
|
|
|
if (\server()->worker_id === 0) {
|
|
|
|
|
|
Console::warning("使用 'sql_config' 配置项和 DB 数据库查询构造器进行查询数据库可能会在下一个大版本中废弃,请使用 'mysql_config' 搭配 doctrine dbal 使用!");
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::warning('详见: `https://framework.zhamao.xin/`');
|
2021-07-09 01:38:30 +08:00
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$origin_conf = ZMConfig::get('global', 'sql_config');
|
2021-07-09 01:38:30 +08:00
|
|
|
|
$real_conf = [
|
2022-03-15 18:05:33 +08:00
|
|
|
|
'host' => $origin_conf['sql_host'],
|
|
|
|
|
|
'port' => $origin_conf['sql_port'],
|
|
|
|
|
|
'username' => $origin_conf['sql_username'],
|
|
|
|
|
|
'password' => $origin_conf['sql_password'],
|
|
|
|
|
|
'dbname' => $origin_conf['sql_database'],
|
|
|
|
|
|
'options' => $origin_conf['sql_options'],
|
2021-07-09 01:38:30 +08:00
|
|
|
|
'unix_socket' => null,
|
|
|
|
|
|
'charset' => 'utf8mb4',
|
2022-03-15 18:05:33 +08:00
|
|
|
|
'pool_size' => 64,
|
2021-07-09 01:38:30 +08:00
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (isset(ZMConfig::get('global', 'mysql_config')['host'])) {
|
|
|
|
|
|
if (ZMConfig::get('global', 'mysql_config')['host'] != '') {
|
|
|
|
|
|
$real_conf = ZMConfig::get('global', 'mysql_config');
|
2021-07-09 01:38:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!empty($real_conf)) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
Console::info('Connecting to MySQL pool');
|
2021-07-09 01:38:30 +08:00
|
|
|
|
ob_start();
|
2022-03-20 16:23:07 +08:00
|
|
|
|
phpinfo(); // 这个phpinfo是有用的,不能删除
|
2021-07-09 01:38:30 +08:00
|
|
|
|
$str = ob_get_clean();
|
|
|
|
|
|
$str = explode("\n", $str);
|
|
|
|
|
|
foreach ($str as $v) {
|
|
|
|
|
|
$v = trim($v);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if ($v == '') {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mb_strpos($v, 'API Extensions') === false) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mb_strpos($v, 'pdo_mysql') === false) {
|
|
|
|
|
|
throw new DbException(zm_internal_errcode('E00028') . '未安装 mysqlnd php-mysql扩展。');
|
2021-07-09 01:38:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
SqlPoolStorage::$sql_pool = new MySQLPool(
|
|
|
|
|
|
(new PDOConfig())
|
|
|
|
|
|
->withHost($real_conf['host'])
|
|
|
|
|
|
->withPort($real_conf['port'])
|
2022-04-10 00:58:07 +08:00
|
|
|
|
// ->withUnixSocket('/tmp/mysql.sock')
|
2022-03-15 18:05:33 +08:00
|
|
|
|
->withDbName($real_conf['dbname'])
|
|
|
|
|
|
->withCharset($real_conf['charset'])
|
|
|
|
|
|
->withUsername($real_conf['username'])
|
|
|
|
|
|
->withPassword($real_conf['password'])
|
|
|
|
|
|
->withOptions($real_conf['options'] ?? [PDO::ATTR_STRINGIFY_FETCHES => false])
|
2021-07-09 01:38:30 +08:00
|
|
|
|
);
|
2022-03-15 18:05:33 +08:00
|
|
|
|
DB::initTableList($real_conf['dbname']);
|
2021-07-09 01:38:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-04-11 23:31:49 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 注册进程容器绑定
|
|
|
|
|
|
*/
|
|
|
|
|
|
private function registerWorkerContainerBindings(Server $server): void
|
|
|
|
|
|
{
|
|
|
|
|
|
$container = WorkerContainer::getInstance();
|
|
|
|
|
|
$container->setLogPrefix("[WorkerContainer#{$server->worker_id}]");
|
|
|
|
|
|
// 路径
|
|
|
|
|
|
$container->instance('path.working', DataProvider::getWorkingDir());
|
|
|
|
|
|
$container->instance('path.source', DataProvider::getSourceRootDir());
|
|
|
|
|
|
$container->alias('path.source', 'path.base');
|
|
|
|
|
|
$container->instance('path.config', DataProvider::getSourceRootDir() . '/config');
|
|
|
|
|
|
$container->instance('path.module_config', ZMConfig::get('global', 'config_dir'));
|
|
|
|
|
|
$container->instance('path.data', DataProvider::getDataFolder());
|
|
|
|
|
|
$container->instance('path.framework', DataProvider::getFrameworkRootDir());
|
|
|
|
|
|
// 基础
|
|
|
|
|
|
$container->instance('server', $server);
|
|
|
|
|
|
$container->instance('worker_id', $server->worker_id);
|
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
}
|