Recently I got asked if I knew about a system that supports multiple session back-ends at once. I didn't know about one and since it's not rocket-science I decided to spent a few hours and whoop something up.
It is a drop-in high-availability storage back-end for PHP sessions by offering a redundant session storage system. It's as easy as including the lib, define the drivers you want to use (e.g. Memcache and MySQL) prepare their configuration/installation and done. If you already have a MySQL server and a Memcache instance running you can set it up in about 5 minutes. It's also easy to extend and write new drivers, just extend the template class and fill in the blanks.
What do(es) my site(s) gain from it?
In short: reliable session data.
If
you want to load-balance your sites and you rely on a state with your
web-application (say.. a shopping cart) this session handler might
offer an easy and fast way to keep that state without having to rely on
the features of the loadbalancer (or architecture). And your session
data is reliable, since it gets written to multiple back-ends.
How does it work?
It
works by overwriting PHP's default session handling (If your site
already does this, this lib has no use for you or you could replace
your implementation with this lib) and handles the drivers you set for
it. When the request is finished all drivers get called with the
session data and it's all written out to the various defined back-ends.
When reading however, only one back-end needs to satisfy the need for
the session data. So in order in which the drivers where registered
they are requested to return the data. When a successful retrieval has
been made the remaining drivers are ignored, so it's wise to register
the fastest one first and ending up with the slowest driver.
What are the cons?
Having
multiple back-ends comes at a cost. It will always be as fast as the
slowest
driver. But on the other hand if you use say 2 or 3 Memcache drivers as
session storage, the chance of failure becomes extremely small and
it's still very fast. However if you use a database over a slow network
connection, you'll probably notice a performance impact. The exact
performance impact is unknown since I didn't perform any benchmarking,
but if you want extreme performance this library isn't what you want in
the first place.
What is the status of the project?
It
is a early work in progress and I wouldn't recommend putting it in
production right away. Test it, play with it and if you find anything
that doesn't work make sure to report it ( http://github.com/Dynom/SessionHandler/issues ). It's free to use and LGPL licensed.