Git地址:https://github.com/nicolasff/phpredis
一、安装:
phpize ./configure make && make install其中,添加PHP扩展需要用到 phpize,所以我们需要安装 php-devel 这个包。
yum install php-devel
然后编译安装phpredis:
git clone git://github.com/nicolasff/phpredis.git
cd phpredis
phpize
./configure --with-php-config=/usr/bin/php-config --enable-redis
make
make install
安装成功后,模块会被安装到系统上,显示如下:
Installing shared extensions: /usr/lib64/php/modules/
执行:ls /usr/lib64/php/modules/
显示有:redis.so
编辑配置文件:php.ini :
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626" //PHP扩展路径
; Enable redis extension module
extension=redis.so //开启redis扩展
最后重启WEB服务器即可!
在命令行里执行:php -m ;发现有redis,表明扩展安装成功!
写个测试脚本:
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
for($i = 0; $i < 100; $i++) {
echo $redis->ping();
}
结果输出:
+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG
+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG
+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG
+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG
+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG+PONG