From 572081cf60954a171c622c617306d46d4c1da16a Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Thu, 24 Jan 2019 11:18:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vilson <545522390@qq.com> --- .../common/Plugins/GateWayWorker/config.php | 12 +++++++++++ .../GateWayWorker/start_businessworker.php | 3 ++- .../Plugins/GateWayWorker/start_gateway.php | 21 ++++++------------- .../Plugins/GateWayWorker/start_register.php | 8 ++++--- extend/service/MessageService.php | 3 ++- 5 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 application/common/Plugins/GateWayWorker/config.php diff --git a/application/common/Plugins/GateWayWorker/config.php b/application/common/Plugins/GateWayWorker/config.php new file mode 100644 index 0000000..6db23fd --- /dev/null +++ b/application/common/Plugins/GateWayWorker/config.php @@ -0,0 +1,12 @@ + '/www/wwwroot/pms/server.pem', // 也可以是crt文件 + 'local_pk' => '/www/wwwroot/pms/server.key', + 'verify_peer' => false, + 'allow_self_signed' => true, //如果是自签名证书需要开启此选项 +));//ssl配置 diff --git a/application/common/Plugins/GateWayWorker/start_businessworker.php b/application/common/Plugins/GateWayWorker/start_businessworker.php index fb5bb16..188e185 100644 --- a/application/common/Plugins/GateWayWorker/start_businessworker.php +++ b/application/common/Plugins/GateWayWorker/start_businessworker.php @@ -17,6 +17,7 @@ use GatewayWorker\Gateway; use GatewayWorker\BusinessWorker; use Workerman\Autoloader; require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/config.php'; // 自动加载类 @@ -27,7 +28,7 @@ $worker->name = 'YourAppBusinessWorker'; // bussinessWorker进程数量 $worker->count = 4; // 服务注册地址 -$worker->registerAddress = '192.168.0.159:2346'; +$worker->registerAddress = SERVER_ADDRESS . ':' . SERVER_PORT; // 如果不是在根目录启动,则运行runAll方法 if(!defined('GLOBAL_START')) diff --git a/application/common/Plugins/GateWayWorker/start_gateway.php b/application/common/Plugins/GateWayWorker/start_gateway.php index 5193330..5b87a97 100644 --- a/application/common/Plugins/GateWayWorker/start_gateway.php +++ b/application/common/Plugins/GateWayWorker/start_gateway.php @@ -16,27 +16,18 @@ use Workerman\Worker; use GatewayWorker\Gateway; require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/config.php'; -$ssl = false; $context = array(); -if ($ssl) { +if (USE_SSL) { // 证书最好是申请的证书 - $context = array( - // 更多ssl选项请参考手册 http://php.net/manual/zh/context.ssl.php - 'ssl' => array( - // 请使用绝对路径 - 'local_cert' => '/www/wwwroot/pms/server.pem', // 也可以是crt文件 - 'local_pk' => '/www/wwwroot/pms/server.key', - 'verify_peer' => false, - 'allow_self_signed' => true, //如果是自签名证书需要开启此选项 - ) - ); + $context = SSL_CONFIG; } // gateway 进程,这里使用Text协议,可以用telnet测试 -$gateway = new Gateway("websocket://192.168.0.159:2345", $context); +$gateway = new Gateway('websocket://' . SERVER_ADDRESS . ':' . CLIENT_PORT, $context); -if ($ssl) { +if (USE_SSL) { // 开启SSL,websocket+SSL 即wss $gateway->transport = 'ssl'; } @@ -51,7 +42,7 @@ $gateway->lanIp = '127.0.0.1'; // 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口 $gateway->startPort = 2900; // 服务注册地址 -$gateway->registerAddress = '192.168.0.159:2346'; +$gateway->registerAddress = SERVER_ADDRESS . ':' . SERVER_PORT; // 心跳间隔 $gateway->pingInterval = 60; diff --git a/application/common/Plugins/GateWayWorker/start_register.php b/application/common/Plugins/GateWayWorker/start_register.php index d7d05b8..ce9dd18 100644 --- a/application/common/Plugins/GateWayWorker/start_register.php +++ b/application/common/Plugins/GateWayWorker/start_register.php @@ -11,19 +11,21 @@ * @link http://www.workerman.net/ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + use Workerman\Worker; use GatewayWorker\Register; + require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/config.php'; // 自动加载类 // register 必须是text协议 -$register = new Register('http://192.168.0.159:2346'); +$register = new Register('http://' . SERVER_ADDRESS . ':' . SERVER_PORT); // 如果不是在根目录启动,则运行runAll方法 -if(!defined('GLOBAL_START')) -{ +if (!defined('GLOBAL_START')) { Worker::runAll(); } diff --git a/extend/service/MessageService.php b/extend/service/MessageService.php index a1e90c9..d885b75 100644 --- a/extend/service/MessageService.php +++ b/extend/service/MessageService.php @@ -3,6 +3,7 @@ namespace service; require_once env('app_path') . 'common/Plugins/GateWayWorker/vendor/autoload.php'; +require_once env('app_path') . 'common/Plugins/GateWayWorker/config.php'; use GatewayWorker\Lib\Gateway; @@ -26,7 +27,7 @@ class MessageService *这里假设GatewayClient和Register服务都在一台服务器上,ip填写127.0.0.1 *注意:ip不能是0.0.0.0 **/ - Gateway::$registerAddress = '192.168.0.159:2346'; + Gateway::$registerAddress = SERVER_ADDRESS . ':' . SERVER_PORT; } public function isUidOnline($uid)