公司开发用到WorkerMan框架,开发RPC服务,用于拉取用户信息和协助用户注册。
workman 官网:http://www.workerman.net/workerman
老版本:
workerman : 3.1.7 GatewayWorker : 1.0.x 查看GatewayWorker版本:http://www.workerman.net/gatewaydoc/faq/get-gateway-version.html
近来,错误日志 workerman.log 中频繁报错:
2016-08-22 14:48:24 createGlobalClientId fail GatewayWorker\Lib\StoreDriver\Redis : 2016-08-22 14:48:24 storeClientAddress fail. 2016-08-22 14:48:25 createGlobalClientId fail GatewayWorker\Lib\StoreDriver\Redis : 2016-08-22 14:48:25 storeClientAddress fail.
根据workerman 框架开发者李亮 的说法,更新GatewayWorker 版本能解决这问题。
老版本文件的目录结构:
service/
├── Applications (目录)
│ └── CHWRPC(目录)
│ ├── Event.php
│ ├── start_businessworker.php
│ └── start_gateway.php
├── GatewayWorker (目录)
├── start.php
├── Workerman (目录)
└── workerman.log
更新GatewayWorker 版本:
升级前准备:
1、备份整个service 目录文件
2、查看官方文档,升级的提醒:http://www.workerman.net/gatewaydoc/appendices/upgrade.html
3、下载并解压源码包:
1)下载页面:http://www.workerman.net/download,下载 GatewayWorker 的 zip压缩文件
2)解压:unzip GatewayWorker-master.zip
3)源码包文件的基本目录结构如下:
GatewayWorker-master/
├── Applications (目录)
│ └── YourApp (目录)
│ ├── Events.php
│ ├── start_businessworker.php
│ ├── start_gateway.php
│ └── start_register.php
├── GatewayWorker (目录)
├── start.php
├── Workerman (目录)
└── workerman.log
升级步骤:
1、停止服务: php start.php stop
2、需要同时将GatewayWorker 和 Workerman 版本更新,不然会报错。将GatewayWorker-master目录中的GatewayWorker 和 Workerman 目录文件,覆盖到 service 目录中
3、
修改文件名,将service/Applications/CHWRPC/Event.php 改名为 Events.php
修改类名, 修改 Events.php 中 class Event 为 class Events
4、拷贝GatewayWorker-master/Applications/YourApp/start_register.php 到 service/Applications/CHWRPC/ 中
<?php /** * This file is part of workerman. * * Licensed under The MIT License * For full copyright and license information, please see the MIT-LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @author walkor<[email protected]> * @copyright walkor<[email protected]> * @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__ . ‘/../../Workerman/Autoloader.php‘; // register 服务必须是text协议 $register = new Register(‘text://0.0.0.0:1236‘); // 如果不是在根目录启动,则运行runAll方法 if(!defined(‘GLOBAL_START‘)) { Worker::runAll(); }
5、新增一行内容到service/Applications/CHWRPC/start_gateway.php
# echo "$gateway->registerAddress = ‘127.0.0.1:1236‘;" >> start_gateway.php## 服务注册地址
## 单机部署ip为127.0.0.1
## 端口与start_register.php中监听端口一致
6、新增一行内容到service/Applications/CHWRPC/start_businessworker.php
# echo "$worker->registerAddress = ‘127.0.0.1:1236‘;" >> start_businessworker.php 注意:端口要和start_register.php中监听端口一致。
7、如果业务有依赖client_id类型,需要将client_id由原来整型改为字符串
8、重启服务,进入debug模式:php start.php start
9、如果没有报错,则将服务放到后台运行:php start.php start -d
新版本:
workerman : 3.3.4 GatewayWorker : 2.0.7
调试模式下,遇到的几个问题:
1、
警告信息:
Deprecated: Lib\MongoDB::_connect(): The Mongo class is deprecated, please use the MongoClient class in /home/service/Applications/CHWRpc/Lib/MongoDB.php on line 1859
分析:
MongoDB.php的第1859行:
$this->_connection = new \Mongo($this->_connection_string, $options);
_connect() 方法里初始化连接时,用到的 Mongo 类已经被废弃了,建议使用 MongoClient 类。
解决:
将_connection() 方法中用到的 Mongo 类改为 MongoClient 类,即:
$this->_connection = new \MongoClient($this->_connection_string, $options);
2、
警告信息:
Strict Standards: Non-static method Modules\NickName::boy_1() should not be called statically in /home/service/Applications/CHWRpc/Modules/NickName.php on line 33
分析:
boy_1() 的声明是一个普通方法,而调用时却采用静态方法调用,因此出现警告信息。
解决方法:
boy_1() 方法的声明修改为: static function boy_1(){ ... }