集成GatewayWorker和Thinkphp5
命令行输入composer命令:composer create-project topthink/think tp5 --prefer-dist稍等片刻thinkphp即可安装完成安装完成thinkphp后再安装gatewayworker命令行切换到tp根目录,运行命令:composer require workerman/gateway-worker-for-win创建push\con
·
命令行输入composer命令:
composer create-project topthink/think tp5 --prefer-dist
稍等片刻thinkphp即可安装完成
安装完成thinkphp后再安装gatewayworker
命令行切换到tp根目录,运行命令:
composer require workerman/gateway-worker-for-win
创建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) {
}
}
}
创建以下启动文件
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启动项目就可以了
更多推荐
已为社区贡献1条内容
所有评论(0)