PHP session handler using Redis, with failover

PHP session handler using Redis, with failover

Here is a a PHP file to include in your project, to add session support with a Redis storage backend, with failover support. It is a custom PHP session handler.

The code use the PHPRedis extension. With this class, you can have a Redis session handler for PHP with failover support : if ou have multiple Redis server, if on is down, an other up server is used. Warning, session are not replicated so in case the main Redis server is down, the session are lost, but your application is still up.

Architecture

If you want to have high-disponibility appliance, you should have something like :

A possible solution is to use your Redis servers for failover : the 1st server is the “master” and in case of failure, the Apache servers automaticaly switch to the 2nd server.

How to use this class

Documentation

In the archive, you can download the RedisSessionHandler.php, the .htaccess config file, and a sample index.php file. Download here the Redis session handler for PHP with failover support.