# swoole 安装

* 安装方式
  * 编译安装方式
  * pecl安装方式
* 配置php.ini
* 快速查看当前swoole的版本
* 升级swoole版本

## 编译方式安装:

```
$ wget http://pecl.php.net/get/swoole-2.2.0.tgz
$ tar -zxvf swoole-2.2.0.tgz
$ cd swoole-2.2.0/
$ phpize
$ ./configure
$ make && make install
```

注意swoole的`./configure`有很多额外参数，可以通过命令`./configure --help`查看,这里均选择默认项),可以参考官方的文档:[编译参数](https://wiki.swoole.com/wiki/page/437.html)

> ./configure \\
>
> \--enable-coroutine \\
>
> \--enable-async-redis \\
>
> make clean && make && sudo make install

编译安装的常见错误参看[官方链接](https://wiki.swoole.com/wiki/page/438.html)

## PECL方式安装:

```
$ pecl install swoole
```

安装指定的版本:

```
$ pecl install swoole-2.1.1
```

资料

[PECL 扩展库安装](https://www.php.net/manual/zh/install.pecl.php)

[swoole -pecl的地址](http://pecl.php.net/package/swoole)

## 配置php.ini

编译安装成功后，修改`php.ini`加入

```
extension=swoole.so
```

通过`php -m`或`phpinfo()`来查看是否成功加载了`swoole.so`，如果没有可能是`php.ini`的路径不对，可以使用`php --ini`来定位到`php.ini`的绝对路径。

针对swoole的一些php.ini配置,请参考官方文档[php.ini选项](https://wiki.swoole.com/wiki/page/352.html)

## 快速查看当前swoole的版本

```
php --ri swoole
```

## 升级swoole版本

**源码编译升级**

直接从github/pecl下载一个新版本，重新安装编译。

* 更新swoole版本，不需要卸载或者删除旧版本swoole，安装过程会覆盖旧版本
* swoole编译安装后没有额外的文件，仅有一个swoole.so，如果是在其他机器编译好的二进制版本。直接互相覆盖swoole.so，即可实现版本切换
* git clone拉取的代码，执行git pull更新代码后，务必要再次执行`phpize、./configure、make clean、make && make install`

**pecl一键升级**

```
pecl upgrade swoole
```

## 资料

[swoole官方文档-编译安装](https://wiki.swoole.com/wiki/page/6.html)

[swoole官方文档-常见错误](https://wiki.swoole.com/wiki/page/438.html)

> 版本类型
>
> * alpha 特性预览版本，表示开发计划中的任务已完成，进行开放预览，可能会存在较多BUG
> * beta 测试版本，表示已经可以用于开发环境测试，可能存在BUG
> * rc\[1-n] 候选发布版本，表示进入发布周期，正在做大范围的测试，在此期间仍可能发现BUG
> * stable 稳定版，表示此版本已完毕，可正式投入使用
>
> 单双数版本
>
> * 单数版本为特性新增版本，主要工作是新增功能特性、代码重构、结构调整。可能会带来一些BUG。
> * 双数版本为问题修复版本，主要工作是修复现有的已知问题、提升性能、完善细节。稳定性更高


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/swoole/ru-men-an-zhuang/swoole-an-zhuang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
