1、官网下载swoole
或
git clone https://gitee.com/swoole/swoole.git
2、安装swoole前必须保证系统已经安装了下列软件
php-5.3.10 或更高版本
gcc-4.4 或更高版本
make
autoconf 需安装m4 安装perl依赖 yum groupinstall perl*
pcre (centos系统可以执行命令:yum install pcre-devel)
3、编译安装
cd swoole
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
4、安装hiredis
下载:https://github.com/redis/hiredis/releases
make -j
sudo make install
sudo ldconfig
5、重新编译swoole
./configure --enable-async-redis --with-php-config=/usr/local/php/bin/php-config
make clean
make -j
sudo make install
6、查看是否安装成功
php --ri swoole
out:
swoole
swoole support => enabled
Version => 4.0.1
Author => tianfeng.han[email: mikan.tenny@gmail.com]
coroutine => enabled
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async redis client => enabled // 表示安装成功
async http/websocket client => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
注:php -m 中swoole扩展消失解决办法
vi ~/.bash_profile
在最后一行添加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
最后再运行
source ~/.bash_profile