1 Star 0 Fork 0

逸诚科技 / top-think_swoole

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
README.md 874 Bytes
Copy Edit Raw Blame History
thinkphp authored 2016-10-05 11:28 . 提交swoole扩展

ThinkPHP 5.0 Swoole 扩展

安装

首先按照Swoole官网说明安装swoole扩展 然后使用 composer require topthink/think-swoole

使用方法

首先创建控制器类并继承 think\Swoole\Server,然后设置属性和添加回调方法

namespace app\index\controller;

use think\Swoole\Server;

class Swoole extends Server
{
	protected $host = '127.0.0.1';
	protected $port = 9502;
	protected $option = [ 
		'worker_num'	=> 4,
		'daemonize'	=> true,
		'backlog'	=> 128
	];

	public function onReceive($server, $fd, $from_id, $data)
	{
		$server->send($fd, 'Swoole: '.$data);
	}
}

支持swoole所有的回调方法定义(回调方法必须是public类型) serverType 属性定义为 socket/http 则支持swoole的swoole_websocket_server和swoole_http_server

在命令行启动服务端

php index.php index/Swoole/start
PHP
1
https://gitee.com/yc_l_zZ/top-think_swoole.git
git@gitee.com:yc_l_zZ/top-think_swoole.git
yc_l_zZ
top-think_swoole
top-think_swoole
master

Search