PHPackages                             redis-session/redis-session - 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. redis-session/redis-session

ActiveLibrary[Caching](/categories/caching)

redis-session/redis-session
===========================

Flexible and feature-complete PHP client library for Redis

v0.0.1(10y ago)0502MITPHPPHP &gt;=5.3.2

Since Dec 18Pushed 10y ago1 watchersCompare

[ Source](https://github.com/zswang/redis-session-php)[ Packagist](https://packagist.org/packages/redis-session/redis-session)[ Docs](https://github.com/TheDeveloper/redis-session-php)[ RSS](/packages/redis-session-redis-session/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

### Redis-backed PHP session handler

[](#redis-backed-php-session-handler)

Stores your $\_SESSION in Redis, using encoding of your choice. Dependency: [predis](https://github.com/nrk/predis) (included as submodule)

### Installation

[](#installation)

Clone:

```
git clone https://TheDeveloper@github.com/TheDeveloper/redis-session-php.git

```

Or include as a submodule:

```
git submodule add https://TheDeveloper@github.com/TheDeveloper/redis-session-php.git

```

### Usage

[](#usage)

```
require('redis-session-php/redis-session.php');
RedisSession::start(); // overrides PHP's default session_save_handler and calls session_start()

// use sessions as normal
$_SESSION['barbara'] = 'streisand';

```

### Synopsis

[](#synopsis)

I wanted to be able to have sessions that were transferable across apps running on different platforms. My intended use case was to have sessions shared between a PHP and Node.js app. Therefore, a Redis datastore acts as a shared store through which all apps can interact with the session data.

If you don't need to serialize in a universal format like JSON, and/or you only wish to use Redis as a session datastore, you can instead use PHP's native seralize() and unserialize(), which will preserve any data structure. Before you call RedisSession::start(), you define which functions to use like so:

```
define('REDIS_SESSION_SERIALIZER', 'serialize');
define('REDIS_SESSION_UNSERIALIZER, 'unserialize');

```

Otherwise, this module serializes your $\_SESSION data using json\_encode by default. The benefit of doing so is that the data is in a standardised format and can be read easily by other languages/platform, such as javascript.

**Warning: encoding to JSON gives no bidirectional support for multidimensional PHP arrays and objects**

The downside is that if a PHP array in your $\_SESSION has more than one dimension (i.e. key =&gt; value nesting), json\_encode converts it to an JSON object.

When we come to reading the data from the session store, json\_decode only converts these objects to multidimensional PHP arrays, or PHP objects. It can't mix them, or recover the original data structures.

As a result, you can only ever have just arrays or just objects in your $\_SESSION. This module returns arrays by default. To switch between the two, use the 2nd (bool) parameter in json\_decode. For only arrays:

```
$_SESSION = json_decode(json_encode($_SESSION), true);

```

For only objects:

```
$_SESSION = json_decode(json_encode($_SESSION));

```

### Testing

[](#testing)

Requires PHP unit. We need to run phpunit with a bootstrap to get around PHP complaining about header output when it tries to start the session:

```
phpunit --bootstrap test/bootstrap.php test/suite.php

```

### Session serialization rant:

[](#session-serialization-rant)

PHP natively uses a very obfuscated serialisation format (apparently only session\_decode() can read it). I don't have time to go digging through PHP source and writing my own adapter.

```
/**
     * RANT: It's seemingly impossible to parse the value in $data.
     * Example:
     *
     * PHP Serialises the following:
     * $_SESSION['test'] = "ohai";
     * $_SESSION['md'] = array('test2' => array('multidimensional' => 'array'));
     * $_SESSION['more'] = new stdClass;
     *
     * Gives:
     *
     * test|s:4:"ohai";md|a:1:{s:5:"test2";a:1:{s:16:"multidimensional";s:5:"array";}}more|O:8:"stdClass":0:{}
     *
     * Where are the delimeters between keys? I'm testing this on PHP 5.3.8 with
     * Suhosin patch, and session_decode() gives false.
     *
     * This is why, on write, we have to access $_SESSION and encode that into
     * a format which is more generic and world readable
     */

```

### The other stuff

[](#the-other-stuff)

Inspired by  and

Check out [http://petermoulding.com/php\_sessions\_and\_serialisation](http://petermoulding.com/php_sessions_and_serialisation) for more info on PHP session serialisation

I also found this  which only sorta works.

LICENSE
-------

[](#license)

(The MIT license)

Copyright (c) Geoff Wagstaff

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95% 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

Unknown

Total

1

Last Release

3847d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/432425?v=4)[TheDeveloper](/maintainers/TheDeveloper)[@TheDeveloper](https://github.com/TheDeveloper)

![](https://avatars.githubusercontent.com/u/536587?v=4)[王集鹄](/maintainers/zswang)[@zswang](https://github.com/zswang)

---

Top Contributors

[![TheDeveloper](https://avatars.githubusercontent.com/u/432425?v=4)](https://github.com/TheDeveloper "TheDeveloper (19 commits)")[![zswang](https://avatars.githubusercontent.com/u/536587?v=4)](https://github.com/zswang "zswang (1 commits)")

---

Tags

redisnosqlpredis

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k318.6M2.7k](/packages/predis-predis)[predis/predis-async

Asynchronous version of Predis

365352.1k](/packages/predis-predis-async)[jamescauwelier/psredis

Sentinel client for the popular php redis client

77397.5k5](/packages/jamescauwelier-psredis)[symfony-bundles/redis-bundle

Symfony Redis Bundle

271.2M6](/packages/symfony-bundles-redis-bundle)[cache/predis-adapter

A PSR-6 cache implementation using Redis (Predis). This implementation supports tags

242.6M13](/packages/cache-predis-adapter)[contributte/redis

Redis client integration into Nette framework

181.7M2](/packages/contributte-redis)

PHPackages © 2026

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