当前位置:   article > 正文

集成GatewayWorker和Thinkphp5_thinkphp集成gatewayworker

thinkphp集成gatewayworker

命令行输入composer命令:

composer create-project topthink/think tp5 --prefer-dist
  • 1

稍等片刻thinkphp即可安装完成
安装完成thinkphp后再安装gatewayworker
命令行切换到tp根目录,运行命令:

composer require workerman/gateway-worker-for-win
  • 1

创建push\controller\Worker.php

<?php
namespace app\push\controller;
use GatewayWorker\Lib\Gateway;
use think\Request;
class Worker extends Server {
    public function __construct(){
        require_once __DIR__ . '/../../../autoload.php';
        $worker = new BusinessWorker();
        $worker->name = 'Business';
        $worker->count = 1;
        $worker->registerAddress = '127.0.0.1:1238';
        $worker->eventHandler = '\\app\\push\\controller\\Worker';
        if(!defined('GLOBAL_START'))
        {
            Worker::runAll();
        }
    } 
    public static function onConnect($client_id) {
    }
    public static function onMessage($client_id, $message) {

    }
    public static function onClose($client_id) {
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

}

创建以下启动文件

start_register.php
start_gateway.php
start_businessworker.php
  • 1
  • 2
  • 3

start_businessworker.php中代码为

define('APP_PATH', __DIR__ . '/../../../application/');
define('BIND_MODULE','push/Worker');
// 加载框架引导文件
require __DIR__ . '/../../../thinkphp/start.php';
  • 1
  • 2
  • 3
  • 4

其他两个启动文件和官方gatewayworker一样

然后双击start_for_win.bat启动项目就可以了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/415034
推荐阅读
相关标签
  

闽ICP备14008679号