环境win7
thinkphp 5.0
think-worker 1.0.*
在thinkphp 5.0上使用workman
参照官网教程步骤如下
安装think-worker 1.0.*版本composer require topthink/think-worker 1.0.*
使用方法
首先创建控制器类并继承 thinkworkerServer,然后设置属性和添加回调方法,支持workerman所有的回调方法定义(回调方法必须是public类型)namespace app\index\controller;
use think\worker\Server;
class Worker extends Server
{
protected $socket = 'http://0.0.0.0:2346';
public function onMessage($connection,$data)
{
$connection->send(json_encode($data));
}
}
在应用根目录增加入口文件 server.php#!/usr/bin/env php
define('APP_PATH', __DIR__ . '/application/');
define('BIND_MODULE','index/Worker');
// 加载框架引导文件
require __DIR__ . '/thinkphp/start.php';
在命令行启动服务端
php server.php start
linux下