tp6-swoole

249 阅读1分钟

tp6安装swoole

composer require topthink/think-swoole:3.1

安装过后,config 文件下会多一个swoole.php文件,修改自己配置的端口

'port'      => env('SWOOLE_PORT', 8090), // 监听端口

可以通过命令行快速生成一个事件监听类

php think make:listener WebsocketEvent

也可以直接使用事件订阅

php think make:subscribe WebsocketEvent

可以在根目录下执行命令  php think swoole start  进行启动程序

image.png

有些因为tp6版本原因,运行的时候出现错误:

PHP Fatal error:  Declaration of think\swoole\App::runningInConsole() must be compatible with think\App::runningInConsole()

可以手动修改源文件,把 vendor/topthink/think-swoole/src/App.php 文件中的runningInConsole方法添加一个返回值的类型就可以了

public function runningInConsole(): bool 
{
... 
}

执行如下命令重启swoole

php think swoole restart

执行如下命令停止swoole

php think swoole stop