作者:徐晨程东_324 | 来源:互联网 | 2023-08-08 22:38
php安装swoole1.下载swoole安装wgethttp:pecl.php.netgetswoole-1.9.1.tgztar-zxvfswoole-1.9.1.tgz
php安装swoole
1. 下载swoole安装
```
wget http://pecl.php.net/get/swoole-1.9.1.tgz
tar -zxvf swoole-1.9.1.tgz
cd swoole-1.9.1
phpize
./configure
make
make install
```
2. 在php.ini添加swoole.so
```
extension=swoole.so
```
3. php文件
```
$server = new swoole_websocket_server("0.0.0.0", 9501);$server->on('open', function (swoole_websocket_server $server, $request) {echo "server: handshake success with fd{$request->fd}\n";
});$server->on('message', function (swoole_websocket_server $server, $frame) {echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";$server->push($frame->fd, "这是服务器消息!");
});$server->on('close', function ($ser, $fd) {echo "client {$fd} closed\n";
});$server->start();
```
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
4. html文件
```
欢迎使用swoole!
```
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
5. 打开防火墙9501端口
```
firewall-cmd --zone=public --add-port=9501/tcp --permanent
systemctl restart firewalld
```
6.. 启动swoole服务
```
php /usr/local/nginx-1.11.5/html/index.php
```
来源:https://blog.csdn.net/aojianmo2012/article/details/55046571