think-swoole的websocket使用(一)

(一)搭建websocket服务

步骤一:给PHP安装swoole扩展

步骤二:进入项目目录,执行 composer require topthink/think-swoole,安装think-swoole扩展

步骤三:修改配置文件swoole.php

  1. server.host 服务器IP,一般为 127.0.0.1(仅监听本地访问)或 0.0.0.0(监听所有IP)
  2. server.port 服务器端口,如果用的是云服务器或者用了宝塔,还需要去云服务器上添加安全组和在宝塔上添加放行端口。
  3. server.options.daemonize 是否守护进程
  4. websocket.enable 打开websocket

 

 

 

 步骤四:在项目目录下执行对应命令,开启服务

启动服务

php think swoole start

停止服务

php think swoole stop

重启服务

php think swoole restart

reload服务

php think swoole reload
posted @ 2023-01-31 15:09  我要的我现在就要  阅读(543)  评论(0)    收藏  举报