Fetch the repository succeeded.
首先按照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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。