Archive for the ‘phpredis’ Category

Install phpredis on Ubuntu

March 25, 2012 10 comments

Tested on Ubuntu 10.10 64bit server edition but should apply to other versions as well.

1) Preparation

sudo apt-get install php5-dev

php5-dev provides the dev library as well as the phpize command which is required for the compiling step
2) Get phpredis source code, should be pretty easy by running

git clone git://

3) Compile and install

cd phpredis
sudo -s make install

4) Enable the phpredis extension

sudo -s
echo "">/etc/php5/conf.d/redis.ini

5) Write a simple php script to test (running on cli would be fine if php5-cli is installed)

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

Prior to try phpredis I was using Rediska as the php redis client. I did some pretty quick and dirty benchmarking comparison and phpredis is clearly a winner here, not surprisingly because phpredis is a compiled extension written in C while Rediska is a pure php library.

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

real 0m13.072s
user 0m6.560s
sys 0m3.620s

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

real 0m21.035s
user 0m12.150s
sys 0m5.050s

and the source code for rediska_set.php:

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

The above tests were conducted on a single-core i3 2.1GHZ Virtualbox guest with 512MB of RAM.

Categories: php, phpredis, redis