The phpredis extension provides an API for communicating with the Redis key-value store. It is released under the PHP License, version 3.01. This code has been developed and maintained by Owlient from November 2009 to March 2011.
Table of contents
- Classes and methods
Everything you should need to install PhpRedis on your system.
phpize ./configure [--enable-redis-igbinary] make && make install
If you would like phpredis to serialize your data using the igbinary library, run configure with
make install copies
redis.so to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in
/etc/php5/conf.d with the following contents:
You can generate a debian package for PHP5, accessible from Apache 2 by running
./mkdeb-apache2.sh or with
This extension exports a single class, Redis (and RedisException used in case of errors). Check out https://github.com/ukko/phpredis-phpdoc for a PHP stub that you can use in your IDE for code completion.
Installation on OSX
If the install fails on OSX, type the following commands in your shell before trying again:
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
If that still fails and you are running Zend Server CE, try this right before "make":
./configure CFLAGS="-arch i386".
Taken from Compiling phpredis on Zend Server CE/OSX .
You can install it using Homebrew:
- Get homebrew-php
brew install php55-redis(or php53-redis, php54-redis)
PHP Session handler
phpredis can be used to store PHP sessions. To do this, configure
session.save_path in your php.ini to tell phpredis where to store the sessions:
session.save_handler = redis session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5"
session.save_path can have a simple
host:port format too, but you need to provide the
tcp:// scheme if you want to use the parameters. The following parameters are available:
- weight (integer): the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, host1 stores 20% of all the sessions (1/(1+2+2)) while host2 and host3 each store 40% (2/1+2+2). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1.
- timeout (float): the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high (86400 seconds).
- persistent (integer, should be 1 or 0): defines if a persistent connection should be used. (experimental setting)
- prefix (string, defaults to "PHPREDIS_SESSION:"): used as a prefix to the Redis key in which the session is stored. The key is composed of the prefix followed by the session ID.
- auth (string, empty by default): used to authenticate with the server pri