swoole1.8.0+版本异步redis安装(本实例为swoole1.8.10版本)详解

时间:2023-03-09 13:03:57
swoole1.8.0+版本异步redis安装(本实例为swoole1.8.10版本)详解

Swoole-1.8.0+版本增加了对异步Redis客户端的支持,基于redis官方提供的hiredis库实现。Swoole提供了__call魔术方法,来映射绝大部分Redis指令(本次安装实例为swoole1.8.10版本)

编译安装hiredis (swoole1.8.10版本异步redis支持必须环境条件)
使用Redis客户端,需要安装hiredis库。下载hiredis源码后,执行

make -j
sudo make install
sudo ldconfig (编译安装完记得执行该命令,否则PHP在引入swoole扩展时将出现类似如下红色字体部分错误)
PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/swoole.so' - libhiredis.so.0.13: cannot open shared object file: No such file or directory in Unknown on line 0
hiredis下载地址:https://github.com/redis/hiredis  (https://github.com/redis/hiredis/releases)
启用异步Redis客户端

编译swoole是,在configure指令中加入--enable-async-redis

./configure --enable-async-redis
make clean
make -j
sudo make install

因为这里用到了swoole的更多扩展组件(ssl 、debug等),所以 摘取天上星 的实际编译命令如下:

./configure --enable-async-redis --with-php-config=/usr/local/php/bin/php-config  --enable-openssl --enable-swoole-debug  --enable-sockets --enable-ringbuffer  --enable-swoole

swoole的./configure有很多额外参数,可以通过./configure --help命令查看,这里均选择默认项)
安装完成后,进入/usr/local/php/etc目录下,打开php.ini文件,在其中加上如下一句:
extension=swoole.so
随后在终端中输入命令 php -m 查看扩展安装情况(或通过phpinfo()函数查看)。如果在列出的扩展中看到了swoole,则说明安装成功。