ThinkPHP使用Swoole需要安装think-swoole Composer包,前提系统已经安装好了Swoole PECL 拓展
tp5的项目根目录下执行composer命令安装think-swoole:
composer require topthink/think-swoole
话不多说,直接上代码:
新建WebSocket.php控制器:
(监听端口要确认服务器放行,宝塔环境还需要添加安全组规则)
<?phpnamespace app\home\controller;use think\swoole\Server;class WebSocket extends Server{ protected $host...
PHP框架 WebSocket 在线聊天阅读全文