PHPackages                             colinmollenhour/php-redis-session-abstract - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. colinmollenhour/php-redis-session-abstract

ActiveLibrary[Caching](/categories/caching)

colinmollenhour/php-redis-session-abstract
==========================================

A Redis-based session handler with optimistic locking

v2.1.2(1y ago)6325.6M↑12.5%48[3 PRs](https://github.com/colinmollenhour/php-redis-session-abstract/pulls)10BSD-3-ClausePHPPHP ^7.4 || ^8.0CI failing

Since Jan 14Pushed 1y ago8 watchersCompare

[ Source](https://github.com/colinmollenhour/php-redis-session-abstract)[ Packagist](https://packagist.org/packages/colinmollenhour/php-redis-session-abstract)[ Docs](https://github.com/colinmollenhour/php-redis-session-abstract)[ RSS](/packages/colinmollenhour-php-redis-session-abstract/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (39)Used By (10)

php-redis-session-abstract
==========================

[](#php-redis-session-abstract)

### A Redis-based session handler with optimistic locking.

[](#a-redis-based-session-handler-with-optimistic-locking)

#### Features:

[](#features)

- When a session's data size exceeds the compression threshold the session data will be compressed.
- Compression libraries supported are 'gzip', 'lzf', 'lz4', and 'snappy'.
    - Gzip is the slowest but offers the best compression ratios.
    - Lzf can be installed easily via PECL.
    - Lz4 is supported by HHVM.
- Compression can be enabled, disabled, or reconfigured on the fly with no loss of session data.
- Expiration is handled by Redis; no garbage collection needed.
- Logs when sessions are not written due to not having or losing their lock.
- Limits the number of concurrent lock requests.
- Detects inactive waiting processes to prevent false-positives in concurrency throttling.
- Detects crashed processes to prevent session deadlocks (Linux only).
- Gives shorter session lifetimes to bots and crawlers to reduce wasted resources.
- Locking can be disabled entirely

#### Locking Algorithm Properties:

[](#locking-algorithm-properties)

- Only one process may get a write lock on a session.
- A process may lose it's lock if another process breaks it, in which case the session will not be written.
- The lock may be broken after `BREAK_AFTER` seconds and the process that gets the lock is indeterminate.
- Only `MAX_CONCURRENCY` processes may be waiting for a lock for the same session or else a ConcurrentConnectionsExceededException will be thrown.

### Compression

[](#compression)

Session data compresses very well so using compression is a great way to increase your capacity without dedicating a ton of RAM to Redis and reducing network utilization. The default `compression threshold` is 2048 bytes so any session data equal to or larger than this size will be compressed with the chosen `compression_lib` which is `gzip` by default. Compression can be disabled by setting the `compression_lib` to `none`. However, both `lzf` and `snappy` offer much faster compression with comparable compression ratios so I definitely recommend using one of these if you have root. lzf is easy to install via pecl:

```
sudo pecl install lzf

```

*NOTE:* If using suhosin with session data encryption enabled (default is `suhosin.session.encrypt=on`), two things:

1. You will probably get very poor compression ratios.
2. Lzf fails to compress the encrypted data in my experience. No idea why...

If any compression lib fails to compress the session data an error will be logged in `system.log` and the session will still be saved without compression. If you have `suhosin.session.encrypt=on` I would either recommend disabling it (unless you are on a shared host since Magento does it's own session validation already) or disable compression or at least don't use lzf with encryption enabled.

Bot Detection
-------------

[](#bot-detection)

Bots and crawlers typically do not use cookies which means you may be storing thousands of sessions that serve no purpose. Even worse, an attacker could use your limited session storage against you by flooding your backend, thereby causing your legitimate sessions to get evicted. However, you don't want to misidentify a user as a bot and kill their session unintentionally. This module uses both a regex as well as a counter on the number of writes against the session to determine the session lifetime.

Using with [Cm\_Cache\_Backend\_Redis](https://github.com/colinmollenhour/Cm_Cache_Backend_Redis)
-------------------------------------------------------------------------------------------------

[](#using-with-cm_cache_backend_redis)

Using Cm\_RedisSession alongside Cm\_Cache\_Backend\_Redis should be no problem at all. However, it is strongly advised to run two separate Redis instances even if they are running on the same server. Running two instances will actually perform better since Redis is single-threaded so on a multi-core server is bound by the performance of a single core. Also it makes sense to allocate varying amounts of memory to cache and sessions and to enforce different "maxmemory" policies. If you absolutely must run one Redis instance for both then just don't use the same 'db' number. But again, just run two Redis instances.

License
-------

[](#license)

```
@copyright  Copyright (c) 2013 Colin Mollenhour (http://colin.mollenhour.com)
This project is licensed under the "New BSD" license (see source).

```

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance49

Moderate activity, may be stable

Popularity63

Solid adoption and visibility

Community39

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 76.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~89 days

Total

35

Last Release

379d ago

Major Versions

v1.5.5 → v2.0.02024-05-15

v1.6.0 → v2.1.02025-05-04

PHP version history (8 changes)v1.0PHP ~5.5.0|~5.6.0|~7.0.0

v1.3.3PHP ~5.5.0|~5.6.0|~7.0.0|~7.1.0

v1.3.8PHP ~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0

v1.4.1PHP ^5.5 || ^7.0

v1.4.3PHP ^5.5 || ^7.0|| ^7.1 || ^7.2

v1.4.4PHP ^5.5 || ^7.0 || ^8.0

v2.1.0PHP ^7.4 || ^8.0

v2.1.1PHP ^7.4 || ^8.0 || ^8.1 || ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38738?v=4)[Colin Mollenhour](/maintainers/colinmollenhour)[@colinmollenhour](https://github.com/colinmollenhour)

---

Top Contributors

[![colinmollenhour](https://avatars.githubusercontent.com/u/38738?v=4)](https://github.com/colinmollenhour "colinmollenhour (139 commits)")[![zamu87](https://avatars.githubusercontent.com/u/22892878?v=4)](https://github.com/zamu87 "zamu87 (7 commits)")[![avoelkl](https://avatars.githubusercontent.com/u/1798594?v=4)](https://github.com/avoelkl "avoelkl (4 commits)")[![nemphys](https://avatars.githubusercontent.com/u/739270?v=4)](https://github.com/nemphys "nemphys (2 commits)")[![sivaschenko](https://avatars.githubusercontent.com/u/2028541?v=4)](https://github.com/sivaschenko "sivaschenko (2 commits)")[![Vinai](https://avatars.githubusercontent.com/u/72463?v=4)](https://github.com/Vinai "Vinai (2 commits)")[![kanevbg](https://avatars.githubusercontent.com/u/11477130?v=4)](https://github.com/kanevbg "kanevbg (2 commits)")[![tmotyl](https://avatars.githubusercontent.com/u/515397?v=4)](https://github.com/tmotyl "tmotyl (2 commits)")[![JacobBrownAustin](https://avatars.githubusercontent.com/u/29411014?v=4)](https://github.com/JacobBrownAustin "JacobBrownAustin (1 commits)")[![jonashrem](https://avatars.githubusercontent.com/u/1112507?v=4)](https://github.com/jonashrem "jonashrem (1 commits)")[![karyna-t](https://avatars.githubusercontent.com/u/55278634?v=4)](https://github.com/karyna-t "karyna-t (1 commits)")[![macoaure](https://avatars.githubusercontent.com/u/11300191?v=4)](https://github.com/macoaure "macoaure (1 commits)")[![abramchenkoaa](https://avatars.githubusercontent.com/u/3831358?v=4)](https://github.com/abramchenkoaa "abramchenkoaa (1 commits)")[![parhamr](https://avatars.githubusercontent.com/u/177123?v=4)](https://github.com/parhamr "parhamr (1 commits)")[![Persata](https://avatars.githubusercontent.com/u/1608834?v=4)](https://github.com/Persata "Persata (1 commits)")[![rbrown](https://avatars.githubusercontent.com/u/233384?v=4)](https://github.com/rbrown "rbrown (1 commits)")[![scottsb](https://avatars.githubusercontent.com/u/6756989?v=4)](https://github.com/scottsb "scottsb (1 commits)")[![tschirmer](https://avatars.githubusercontent.com/u/3872130?v=4)](https://github.com/tschirmer "tschirmer (1 commits)")[![vdechenaux](https://avatars.githubusercontent.com/u/1501825?v=4)](https://github.com/vdechenaux "vdechenaux (1 commits)")[![viable-hartman](https://avatars.githubusercontent.com/u/1300504?v=4)](https://github.com/viable-hartman "viable-hartman (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/colinmollenhour-php-redis-session-abstract/health.svg)

```
[![Health](https://phpackages.com/badges/colinmollenhour-php-redis-session-abstract/health.svg)](https://phpackages.com/packages/colinmollenhour-php-redis-session-abstract)
```

###  Alternatives

[colinmollenhour/cache-backend-redis

Zend\_Cache backend using Redis with full support for tags.

38522.9M13](/packages/colinmollenhour-cache-backend-redis)[resque/php-resque

Redis backed library for creating background jobs and processing them later. Based on resque for Ruby.

2371.8M7](/packages/resque-php-resque)[rhubarbgroup/redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

51795.3k1](/packages/rhubarbgroup-redis-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
