swoole安装基本配置

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文件

```
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();
```

4. html文件

```



    欢迎使用swoole!



欢迎使用swoole!

```

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
```

你可能感兴趣的:(Centos7-2,PHP基础知识,Web后端)