啟動(dòng)時(shí)無(wú)響應(yīng),
root@lsy-PC:/home/wwwroot/wecharge-server# sudo php gateway.php start
/home/wwwroot/wecharge-server/thinkphp/library/think/Debug.php:193:
array(3) {
[0] =>
string(39) "\app\gateway\controller\EventsWebsocket"
[1] =>
string(36) "\app\gateway\controller\EventsHuaxia"
[2] =>
string(36) "\app\gateway\controller\EventsGuoyao"
}
Workerman[gateway.php] start in DEBUG mode
------------------------------------------------- WORKERMAN -------------------------------------------------
Workerman version:4.0.6 PHP version:7.3.11
-------------------------------------------------- WORKERS --------------------------------------------------
proto user worker listen processes status
tcp root Register text://0.0.0.0:1239 1 [OK]
tcp root websocketBusinessWorker none 1 [OK]
tcp root websocket websocket://0.0.0.0:8001 4 [OK]
tcp root Register text://0.0.0.0:1238 1 [OK]
tcp root huaxiaBusinessWorker none 1 [OK]
tcp root huaxia huaxia://0.0.0.0:8989 4 [OK]
tcp root Register text://0.0.0.0:1240 1 [OK]
tcp root GuoyaoBusinessWorker none 1 [OK]
tcp root Guoyao guoyao://0.0.0.0:8990 4 [OK]
-------------------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
^[[A^CWorkerman[gateway.php] stopping ...
***** app\gateway\controller\EventsWebsocket onWorkerStart *****
^[[Aworker[websocket:8540] exit with status 9
worker[websocket:8542] exit with status 9
worker[websocket:8543] exit with status 9
worker[huaxiaBusinessWorker:8545] exit with status 9
worker[huaxia:8547] exit with status 9
worker[websocketBusinessWorker:8539] exit with status 9
worker[Guoyao:8553] exit with status 9
worker[huaxia:8549] exit with status 9
worker[Guoyao:8552] exit with status 9
worker[GuoyaoBusinessWorker:8551] exit with status 9
worker[Register:8550] exit with status 9
worker[Guoyao:8554] exit with status 9
worker[Guoyao:8555] exit with status 9
worker[huaxia:8546] exit with status 9
worker[huaxia:8548] exit with status 9
worker[Register:8538] exit with status 9
Workerman[gateway.php] has been stopped
php gateway.php status 查詢狀態(tài)就會(huì)卡住
我workerman只啟動(dòng)了自定義通訊協(xié)議和websocket , 但是一啟動(dòng)服務(wù) , 混著把我的nginx的http服務(wù)也卡住
以上問(wèn)題只會(huì)在本地linux開(kāi)發(fā)時(shí)出現(xiàn) ,代碼thinkphp5整合到一起 ,在Centos的服務(wù)器不會(huì)出現(xiàn) , 應(yīng)該是環(huán)境配置問(wèn)題
本地環(huán)境linux 安裝的LNMP
服務(wù)器CentOS 也是安裝的LNMP
<?php
namespace app\gateway\controller;
use Workerman\Worker;
use GatewayWorker\Register;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
class Run
{
public function __construct() {
$this->hardware();
$this->websocket();
// 運(yùn)行所有Worker;
Worker::runAll();
}
public function hardware() {
// 初始化register
new Register('text://0.0.0.0:1238');
//初始化 bussinessWorker 進(jìn)程
$worker = new BusinessWorker();
$worker->name = 'BusinessWorker';
$worker->count = 1;
$worker->registerAddress = '127.0.0.1:1238';
// 設(shè)置處理業(yè)務(wù)的類(lèi),此處制定Events的命名空間
$worker->eventHandler = '\app\gateway\controller\EventsDevice';
// 初始化 gateway 進(jìn)程
// 證書(shū)最好是申請(qǐng)的證書(shū)
$context = array(
// 更多ssl選項(xiàng)請(qǐng)參考手冊(cè) http://php.net/manual/zh/context.ssl.php
'ssl' => array(
// 請(qǐng)使用絕對(duì)路徑
'local_cert' => APP_PATH . '/common/cert/3893683_.pem', // 也可以是crt文件
'local_pk' => APP_PATH . '/common/cert/3893683_.key',
'verify_peer' => false,
// 'allow_self_signed' => true, //如果是自簽名證書(shū)需要開(kāi)啟此選項(xiàng)
)
);
$gateway = new Gateway("Communication://0.0.0.0:8989", $context);
// $gateway->transport = 'ssl';
$gateway->protocol = '\\app\\gateway\\protocols\\Communication';
$gateway->name = 'huaxia pile';
$gateway->count = 4;
$gateway->lanIp = '127.0.0.1';
$gateway->startPort = 2900;
$gateway->registerAddress = '127.0.0.1:1238';
//心跳時(shí)間
$gateway->pingInterval = 60; //每次心跳時(shí)間
$gateway->pingNotResponseLimit = 5; //無(wú)響應(yīng)心跳次數(shù)限制
// $gateway->pingData = '{"action": "system/ping"}';//響應(yīng)心跳數(shù)據(jù)(不建議)
}
//websocket 的 gateway 服務(wù)
public function websocket() {
// 初始化register
new Register('text://0.0.0.0:1239');
//初始化 bussinessWorker 進(jìn)程
$worker = new BusinessWorker();
$worker->name = 'webBusinessWorker';
$worker->registerAddress = '127.0.0.1:1239';
// 設(shè)置處理業(yè)務(wù)的類(lèi),此處制定Events的命名空間
$worker->eventHandler = '\app\gateway\controller\EventsWebsocket';
$context = array(
// 更多ssl選項(xiàng)請(qǐng)參考手冊(cè) http://php.net/manual/zh/context.ssl.php
'ssl' => array(
// 請(qǐng)使用絕對(duì)路徑
'local_cert' => APP_PATH . '/common/cert/3893683.pem', // 也可以是crt文件
'local_pk' => APP_PATH . '/common/cert/3893683.key',
'verify_peer' => false,
// 'allow_self_signed' => true, //如果是自簽名證書(shū)需要開(kāi)啟此選項(xiàng)
)
);
$websocket = new Gateway("websocket://0.0.0.0:8001", $context);
$websocket->transport = 'ssl';
$websocket->name = 'websocket';
$websocket->count = 4;
$websocket->lanIp = '127.0.0.1';
$websocket->startPort = 3000;
$websocket->registerAddress = '127.0.0.1:1239';
}
}
源碼修改部分
//修復(fù)一個(gè)workermanBUG(無(wú)法解析自定義通訊協(xié)議文件)
// ./vendor/workerman/workerman/Worker.php 的 parseSocketAddress()
把
$this->protocol = \substr($scheme, 0, 1) === '\\' ? $scheme : '\\Protocols\\' . $scheme;
改成
if(empty($this->protocol)) {
$this->protocol = \substr($scheme, 0, 1) === '\\' ? $scheme : '\\Protocols\\' . $scheme;
}
http://doc.workerman.net/debug/busy-process.html
根據(jù)文檔調(diào)試下看下進(jìn)程卡在哪個(gè)系統(tǒng)調(diào)用上
因?yàn)閜hp gateway.php status無(wú)響應(yīng) ,只能用workerman.log啟動(dòng)日志的pid
root@lsy-PC:/home/wwwroot/wecharge-server# strace -ttp 28323
strace: Process 28323 attached
09:53:06.674526 wait4(-1,