公司開發用到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<walkor@workerman.net> * @copyright walkor<walkor@workerman.net> * @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(){ ... }