集成GatewayWorker和Thinkphp5

命令行输入composer命令:

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

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

composer require workerman/gateway-worker-for-win

创建push\controller\Worker.php

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) {
    }
}

}

创建以下启动文件

start_register.php
start_gateway.php
start_businessworker.php

start_businessworker.php中代码为

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

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

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

你可能感兴趣的:(PHP)