workerman可以连接的上,到是用GatewayWorker用前端链接的时候不行而且启动没端口号
估计报错了,不知道你怎么写的,用tp5.1有集成Gateway
就是按照tp5.1教程搞的,启动没有端口很郁闷
https://blog.csdn.net/qq_27238185/article/details/81477303?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf
5.1 要那个教程干啥,tp官方有集成, 这是 config 里面的 gateway_worker.php 'businessWorker' => [ 'name' => 'BusinessWorker', 'count' => 1, //重写Events类 'eventHandler' => 'app\worker\controller\GateWayMsg', ],
然后 GateWayMsg 代码
<?php
namespace app\worker\controller;
use GatewayWorker\Lib\Gateway; use think\worker\Events; use Workerman\Lib\Timer; use Workerman\Worker;
class GateWayMsg extends Events {
/** * onMessage 事件回调 * 当客户端发来数据(Gateway进程收到数据)后触发 * * @access public * @param int $client_id * @param mixed $data * @return void */ public static function onMessage($client_id, $data) { $data = json_decode($data, true); } // /** * onClose 事件回调 当用户断开连接时触发的方法 * * @param integer $client_id 断开连接的客户端client_id * @return void */ public static function onClose($client_id) { GateWay::sendToAll("client[$client_id] logout\n"); } /** * onConnect 事件回调 * 当客户端连接上gateway进程时(TCP三次握手完毕时)触发 * * @access public * @param int $client_id * @return void */ public static function onConnect($client_id) { // 连接到来后,定时10秒关闭这个链接,需要10秒内发认证并删除定时器阻止关闭连接的执行 $auth_timer_id = Timer::add(10, function ($client_id) { Gateway::closeClient($client_id); }, array($client_id), false); Gateway::updateSession($client_id, array('auth_timer_id' => $auth_timer_id)); } public static function onWorkerStart(Worker $businessWorker) { parent::onWorkerStart($businessWorker); // TODO: Change the autogenerated stub } /** * onWorkerStop 事件回调 * 当businessWorker进程退出时触发。每个进程生命周期内都只会触发一次。 * * @param \Workerman\Worker $businessWorker * @return void */ public static function onWorkerStop(Worker $businessWorker) { echo "WorkerStop\n"; }
}
最后 php think worker:gateway 启动,这个要在linux运行
@5433:谢谢指导
估计报错了,不知道你怎么写的,用tp5.1有集成Gateway
就是按照tp5.1教程搞的,启动没有端口很郁闷
按照这个教程搞的
https://blog.csdn.net/qq_27238185/article/details/81477303?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf
5.1 要那个教程干啥,tp官方有集成,
这是 config 里面的 gateway_worker.php
'businessWorker' => [
'name' => 'BusinessWorker',
'count' => 1,
//重写Events类
'eventHandler' => 'app\worker\controller\GateWayMsg',
],
然后 GateWayMsg 代码
<?php
namespace app\worker\controller;
use GatewayWorker\Lib\Gateway;
use think\worker\Events;
use Workerman\Lib\Timer;
use Workerman\Worker;
class GateWayMsg extends Events
{
}
最后 php think worker:gateway 启动,这个要在linux运行
@5433:谢谢指导