Think before you speak, read before you think.

在ubuntu下安装phpredis

by

in

翻译自:http://ricochen.wordpress.com/2012/03/25/install-phpredis-on-ubuntu/ 打不开不怪我。

在12.04 TLS下测试可用。

1) 准备工作

 sudo apt-get install php5-dev

php5-dev 提供了开发库及编译必须的phpize工具

2) 获取phpredis源代码

git clone git://github.com/nicolasff/phpredis.git

3) 编译安装

cd phpredis
phpize5
./configure
make
sudo -s make install

4) 启用phpredis扩展

sudo -s
echo "extension=redis.so">/etc/php5/conf.d/redis.ini
exit

5) 写一段php代码进行测试 (在命令行下测试需要先安装好php5-cli)。以下是分别使用phpredis与Rediska(https://github.com/Shumkov/Rediska)进行测试。很明显使用c编写的phpredis插件性能高于php库Rediska。

phpredis_set.php内容和测试结果:

<?php
 // phpredis_set.php
 $redis=new Redis() or die("Can'f load redis module.");
 $redis->connect('127.0.0.1');
 $redis->set('set_testkey', 1);

time for i in `seq 1 1000`; do php phpredis_set.php; done

real 0m16.352s
user 0m8.105s
sys 0m5.784s

rediska_set.php内容和测试结果:

<?php
 require_once 'Rediska.php';
 $rediska=new Rediska();
 $rediska->set('set_testkey', 1);

time for i in `seq 1 1000`; do php rediska_set.php; done

real 0m21.075s
user 0m12.657s
sys 0m6.228s


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *