Install phpredis on Ubuntu
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://github.com/nicolasff/phpredis.git
3) Compile and install
cd phpredis phpize ./configure make sudo -s make install
4) Enable the phpredis extension
sudo -s echo "extension=redis.so">/etc/php5/conf.d/redis.ini exit
5) Write a simple php script to test (running on cli would be fine if php5-cli is installed)
<?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);
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:
<?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.
Thanks, this was useful to me.
Thanks a lot Rico! You nailed it for me
No problem. Glad it helps.
Great guide, great to see the comparison of the two! One note, I had to copy the compiled module to my PHP modules directory to get it working (Ubuntu 12.04). Cheers!
Hrmmm, must be an issue with that server, other server copied it over fine. Still a great guide, cheers!
Thanks, it worked like a charm!
You can check successfull installation in one line:
php -r “var_dump(get_class_methods(Redis));”
shall print a list of availible methods.
That’s clever! Thanks for sharing.
THX!