<?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;
// 證書最好是申請的證書
$context = array(
// 更多ssl選項請參考手冊 http://php.net/manual/zh/context.ssl.php
'ssl' => array(
// 請使用絕對路徑
'local_cert' => '/etc/ssl/certs/1_bundle.crt', // 也可以是crt文件
'local_pk' => '/etc/ssl/certs/2_.key',
'verify_peer' => false,
// 'allow_self_signed' => true, //如果是自簽名證書需要開啟此選項
)
);
// websocket協(xié)議(端口任意,只要沒有被其它程序占用就行)
$gateway = new Gateway("websocket://0.0.0.0:6686", $context);
// 開啟SSL,websocket+SSL 即wss
$gateway->transport = 'ssl';
// gateway名稱,status方便查看
$gateway->name = 'WebsocketSSL';
// 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 = 11900;
// 服務(wù)注冊地址
$gateway->registerAddress = '127.0.0.1:21238';
// 心跳間隔
$gateway->pingInterval = 60;
//如果設(shè)置為0代表客戶端不用發(fā)送回應(yīng)數(shù)據(jù)
$gateway->pingNotResponseLimit = 1;
// 心跳數(shù)據(jù)
//$gateway->pingData = '{"type":"ping"}';
$gateway->pingData = '';
$gateway->onConnect = function($connection)
{
$connection->onWebSocketConnect = function($connection , $http_header)
{
};
};
$gateway = new Gateway("websocket://0.0.0.0:6687");
$gateway->name = 'Websocket Forward Gateway';
$gateway->count = 4;
$gateway->lanIp = '127.0.0.1';
$gateway->startPort = 13900;
$gateway->registerAddress = '127.0.0.1:21238';
// 心跳間隔
$gateway->pingInterval = 120;
//如果設(shè)置為0代表客戶端不用發(fā)送回應(yīng)數(shù)據(jù)
$gateway->pingNotResponseLimit = 0;
// 心跳數(shù)據(jù)
//$gateway->pingData = '{"type":"ping"}';
$gateway->pingData = '';
// gateway 進程,這里使用Text協(xié)議,可以用telnet測試
$gateway = new Gateway("tcp://0.0.0.0:6685");
// gateway名稱,status方便查看
$gateway->name = 'SCADAGateway';
// 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 = 12900;
// 服務(wù)注冊地址
$gateway->registerAddress = '127.0.0.1:21238';
// 心跳間隔
//$gateway->pingInterval = 15;
//如果設(shè)置為0代表客戶端不用發(fā)送回應(yīng)數(shù)據(jù)
//$gateway->pingNotResponseLimit = 0;
// 心跳數(shù)據(jù)
//$gateway->pingData = '{"type":"ping"}';
/*
// 當(dāng)客戶端連接上來時,設(shè)置連接的onWebSocketConnect,即在websocket握手時的回調(diào)
$gateway->onConnect = function($connection)
{
$connection->onWebSocketConnect = function($connection , $http_header)
{
};
};
*/
// 如果不是在根目錄啟動,則運行runAll方法
if(!defined('GLOBAL_START')) {
Worker::runAll();
}
1、針對端口6687的設(shè)置,依然是執(zhí)行60s不回復(fù)則斷開
2、懷疑是按了最小粒度的設(shè)置執(zhí)行了
3、如何分開設(shè)置呢?
官方支持兩種心跳機制:
1、客戶端定時發(fā)送心跳(推薦)
2、服務(wù)端主動發(fā)送心跳(不推薦)
再看看6687端口的設(shè)置:$gateway->pingNotResponseLimit = 0;
$gateway->pingData = '';
這兩個參數(shù)不能同時邏輯空,否則就相當(dāng)于沒做任何心跳策略,具體參考手冊。