## 安装TPcomposer create-project topthink/think tpswow## 安装swowcomposer require swow/swow## 修改composer.json添加autoload psr-4命名空间"think\\swow\\": "swow"![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/179fb876189e46c781c6cb754886b0ac.png)## 添加配置文件到config下swow.php<?phpdeclare(strict_types=1);use Swow\Socket;use think\swow\websocket\Handler;return [ 'http' => [ 'enable' => true, 'host' => '0.0.0.0', 'port' => 8089, 'options' => [], 'flags' => Socket::BIND_FLAG_NONE, ], 'websocket' => [ 'enable' => false, 'handler' => Handler::class, 'ping_interval' => 25, 'ping_timeout' => 60, 'room' => [ 'type' => 'redis', 'redis' => [ 'host' => '127.0.0.1', 'port' => 6379, 'max_active' => 3, 'max_wait_time' => 5, ], ], 'listen' => [], 'subscribe' => [], ], //连接池 'pool' => [ 'db' => [ 'enable' => true, 'max_active' => 3, 'max_wait_time' => 5, ], 'cache' => [ 'enable' => true, 'max_active' => 3, 'max_wait_time' => 5, ], //自定义连接池 ], 'ipc' => [ // swow是单进程,默认是不需要ipc的 'enable' => false, 'type' => 'redis', 'redis' => [ 'host' => '127.0.0.1', 'port' => 6379, 'max_active' => 3, 'max_wait_time' => 5, ], ], // ipc标识, 可选getmypid、gethostname等(pid不能含有.) 'get_pid_func' => 'getmypid', // 每个worker里需要预加载以共用的实例 'concretes' => [], // 重置器 'resetters' => [], // 每次请求前需要清空的实例 'instances' => [], // 每次请求前需要重新执行的服务 'services' => [],];
下载tp-swow【根目录的swow文件夹】,忘记从哪里下载的了。我把本地的压缩上传。tp+swow启动服务的代码在根目录swow启动服务[根目录server文件]php server
启动之后可以访问 http://127.0.0.1:8089