workman啟動后正常運行一段時間到了晚上固定時間服務端收不到客戶端的信息
使用后臺運行啟動workman gateway服務 到了晚上八點多 會提示內(nèi)部端口被拒絕 然后服務端收不到客戶端的信息,通過TCP測試軟件,還能夠正常連接,能夠向服務端發(fā)送消息 但是收不到回復,檢查workman的進程還在運行,使用restart重啟服務后 服務端又能夠收到消息并正確回應客戶端
<?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://wtbis.cn/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
// 自動加載類
require_once __DIR__ . '/../../vendor/autoload.php';
// gateway 進程,這里使用Text協(xié)議,可以用telnet測試
$gateway = new Gateway("tcp://0.0.0.0:8383");
// gateway名稱,status方便查看
$gateway->name = 'litapowerGateway';
// gateway進程數(shù)
$gateway->count = 4;
// 本機ip,分布式部署時使用內(nèi)網(wǎng)ip
$gateway->lanIp = '127.0.0.1';
// 內(nèi)部通訊起始端口,假如$gateway->count=4,起始端口為4000
// 則一般會使用4000 4001 4002 4003 4個端口作為內(nèi)部通訊端口
$gateway->startPort = 2900;
// 服務注冊地址
$gateway->registerAddress = '127.0.0.1:1238';
// 心跳間隔
//$gateway->pingInterval = 10;
// 心跳數(shù)據(jù)
//$gateway->pingData = '{"type":"ping"}';
/*
// 當客戶端連接上來時,設(shè)置連接的onWebSocketConnect,即在websocket握手時的回調(diào)
$gateway->onConnect = function($connection)
{
$connection->onWebSocketConnect = function($connection , $http_header)
{
// 可以在這里判斷連接來源是否合法,不合法就關(guān)掉連接
// $_SERVER['HTTP_ORIGIN']標識來自哪個站點的頁面發(fā)起的websocket鏈接
if($_SERVER['HTTP_ORIGIN'] != 'http://kedou.workerman.net')
{
$connection->close();
}
// onWebSocketConnect 里面$_GET $_SERVER是可用的
// var_dump($_GET, $_SERVER);
};
};
*/
// 如果不是在根目錄啟動,則運行runAll方法
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
CentOS Linux release 7.9.2009 (Core) workman:4.0.27
看下workerman.log日志,有問題時運行 php start.php status 看下進程狀態(tài)。
感覺是你沒有使用守護進程運行workerman
已經(jīng)是守護進程模式運行的 php start.php status 也是正常的 客戶端還能正常創(chuàng)建連接 只是無法接受消息 workman.log的報錯都是這種pid:8137 Exception: can not connect to tcp://127.0.0.1:3100 Connection refused in /home/wwwroot/server/vendor/workerman/gateway-worker/src/Lib/Gateway.php:1153 出現(xiàn)這種錯誤就會接收不到客戶端的信息