From 0eb6d8607d501ef013c9b599be095ee8f83b6558 Mon Sep 17 00:00:00 2001 From: weiz Date: Sat, 21 Oct 2023 11:56:43 +0800 Subject: [PATCH] fixed --- app/common/controller/ImController.php | 2 +- {extend => app/common/service}/workerim/Events.php | 3 ++- .../service}/workerim/start_businessworker.php | 14 +++++++------- .../common/service}/workerim/start_gateway.php | 10 +++++----- .../common/service}/workerim/start_register.php | 4 ++-- start.php | 2 +- start_for_win.bat | 2 +- 7 files changed, 19 insertions(+), 18 deletions(-) rename {extend => app/common/service}/workerim/Events.php (94%) rename {extend => app/common/service}/workerim/start_businessworker.php (57%) rename {extend => app/common/service}/workerim/start_gateway.php (73%) rename {extend => app/common/service}/workerim/start_register.php (66%) diff --git a/app/common/controller/ImController.php b/app/common/controller/ImController.php index 4322edf1d..17cf6cac4 100644 --- a/app/common/controller/ImController.php +++ b/app/common/controller/ImController.php @@ -17,7 +17,7 @@ class ImController extends BaseLikeAdminController public function __construct(App $app) { parent::__construct($app); - Gateway::$registerAddress = "172.19.97.179:1256"; + Gateway::$registerAddress = env('worker.address').':'.env('worker.port'); } //获取场景值 diff --git a/extend/workerim/Events.php b/app/common/service/workerim/Events.php similarity index 94% rename from extend/workerim/Events.php rename to app/common/service/workerim/Events.php index 996076ea4..2aa21425b 100644 --- a/extend/workerim/Events.php +++ b/app/common/service/workerim/Events.php @@ -1,7 +1,8 @@ name = 'PushBusinessWorker'; $worker->count = 4; // 服务注册地址 -$worker->registerAddress = '172.19.97.179:1256'; +$worker->registerAddress = env('worker.address').':'.env('worker.port'); // 注册服务类 -$worker->eventHandler = 'workerim\Events'; +$worker->eventHandler = 'app\common\service\workerim\Events'; // 如果不是在根目录启动,则运行runAll方法 if(!defined('GLOBAL_START')) diff --git a/extend/workerim/start_gateway.php b/app/common/service/workerim/start_gateway.php similarity index 73% rename from extend/workerim/start_gateway.php rename to app/common/service/workerim/start_gateway.php index 7437e0276..5c653259f 100644 --- a/extend/workerim/start_gateway.php +++ b/app/common/service/workerim/start_gateway.php @@ -4,26 +4,26 @@ use \Workerman\Worker; use \GatewayWorker\Gateway; // 自动加载类 -require_once __DIR__ . '/../../vendor/autoload.php'; +require_once __DIR__ . '/../../../../vendor/autoload.php'; // gateway 进程,这里使用Text协议,可以用telnet测试 $gateway = new Gateway("Websocket://0.0.0.0:8282"); // gateway名称,status方便查看 -$gateway->name = 'worker_task_im'; +$gateway->name = env('worker.work_name'); // gateway进程数,一般设置2个就足够 $gateway->count = 4; // 本机ip,分布式部署时使用内网ip -$gateway->lanIp = '172.19.97.179'; +$gateway->lanIp = env('worker.address'); // 内部通讯起始端口,假如$gateway->count=2,起始端口为2900 // 则一般会使用3900 3901 3902 3903 4个端口作为内部通讯端口 -$gateway->startPort = 3900; +$gateway->startPort = env('worker.start_port'); // 服务注册地址 -$gateway->registerAddress = '172.19.97.179:1256'; +$gateway->registerAddress = env('worker.address').':'.env('worker.port'); // 心跳间隔 $gateway->pingInterval = 20; diff --git a/extend/workerim/start_register.php b/app/common/service/workerim/start_register.php similarity index 66% rename from extend/workerim/start_register.php rename to app/common/service/workerim/start_register.php index 5d4854240..aa0d8b34f 100644 --- a/extend/workerim/start_register.php +++ b/app/common/service/workerim/start_register.php @@ -3,10 +3,10 @@ use \Workerman\Worker; use \GatewayWorker\Register; // 自动加载类 -require_once __DIR__ . '/../../vendor/autoload.php'; +require_once __DIR__ . '/../../../../vendor/autoload.php'; // register 必须是text协议,切记不能将register端口开放给外网 -$register = new Register('text://172.19.97.179:1256'); +$register = new Register('text://'.env('worker.address').':'.env('worker.port')); // 如果不是在根目录启动,则运行runAll方法 if(!defined('GLOBAL_START')) diff --git a/start.php b/start.php index c29a03638..72b64ee8f 100644 --- a/start.php +++ b/start.php @@ -29,7 +29,7 @@ define('GLOBAL_START', 1); require_once __DIR__ . '/vendor/autoload.php'; // 加载所有Applications/*/start.php,以便启动所有服务 -foreach(glob(__DIR__.'/extend/workerim/start*.php') as $start_file) +foreach(glob(__DIR__.'/app/common/service/workerim/start*.php') as $start_file) { require_once $start_file; } diff --git a/start_for_win.bat b/start_for_win.bat index 604c848f8..bbcd605c6 100644 --- a/start_for_win.bat +++ b/start_for_win.bat @@ -1,3 +1,3 @@ CHCP 65001 -php extend\workerim\start_register.php extend\workerim\start_gateway.php extend\workerim\start_businessworker.php +php app\common\service\workerim\start_register.php app\common\service\workerim\start_gateway.php app\common\service\workerim\start_businessworker.php pause \ No newline at end of file