安装swoole

下载swoole包
wget https://github.com/swoole/swoole-src/archive/swoole-1.7.6-stable.tar.gz

解压
tar zxvf swoole-1.7.6-stable.tar.gz

进入目录文件
cd swoole-1.7.6-stable

准备扩展安装编译环境
phpize

配置:(–with-php-config==后面是你自己的php-config位置)
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

php加载swoole扩展

在php配置文件加入 extension=swoole.so

重启服务

service php-fpm restart
service nginx restart

检查phpinfo()出现swoole,则安装成功

swoole安装和基本使用

基本使用

1.创建TCP服务 server.php
swoole安装和基本使用
2.启动TCP服务
php server.php

查看9501端口已被监听:netstat -an | grep 9501
swoole安装和基本使用
使用telnet连接TCP服务,输入hello,服务器返回hello即测试成功:
(如果telnet工具没有安装,执行yum install telnet 、yum install telnet-server)
swoole安装和基本使用
3.写一个TCP客户端连接TCP服务器端:tcp_client.php
swoole安装和基本使用
执行它
swoole安装和基本使用
表示连接成功
4.创建udp服务器 udp_server.php 并运行 php udp_server.php
swoole安装和基本使用
使用netcat连接UDP服务,输入hello,服务器返回hello即测试成功(CentOS):
swoole安装和基本使用
(如果没有安装netcat监听器,执行yum install -y nc)

5.创建Web服务器 http_server.php
swoole安装和基本使用
6.启动服务,php http_server.php,浏览器访问127.0.0.1:9501

swoole安装和基本使用
7.创建WebSocket服务器 ws_server.php:并运行:php ws_server.php

swoole安装和基本使用
8.前端页面js监听:web.html(127.0.0.1改成你的主机地址)
swoole安装和基本使用
9.访问它,
swoole安装和基本使用
服务器端返回连接参数:
swoole安装和基本使用
以上就是swoole的简单应用

相关文章:

  • 2021-06-10
  • 2022-12-23
  • 2022-01-01
  • 2021-10-29
  • 2021-11-05
  • 2021-07-14
  • 2022-02-07
  • 2021-12-25
猜你喜欢
  • 2021-05-31
  • 2021-11-03
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案