PHPackages                             ericmann/sessionz - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ericmann/sessionz

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ericmann/sessionz
=================

PHP Session Manager Interface

0.5.1(2mo ago)585.4k72MITPHPPHP &gt;=7.4CI failing

Since Nov 26Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/ericmann/sessionz)[ Packagist](https://packagist.org/packages/ericmann/sessionz)[ RSS](/packages/ericmann-sessionz/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (5)Versions (8)Used By (2)

PHP Sessionz [![CI](https://github.com/ericmann/sessionz/actions/workflows/ci.yml/badge.svg)](https://github.com/ericmann/sessionz/actions/workflows/ci.yml) [![Latest Stable Version](https://camo.githubusercontent.com/e7c022cff21d6fca2121e4e95eb85de88dc4cdce547a7942c6187c733150c73f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f657269636d616e6e2f73657373696f6e7a2e737667)](https://packagist.org/packages/ericmann/sessionz) [![License](https://camo.githubusercontent.com/d6d30cc572bd2c8aa5d5c3930386b8f909cf590b5c881caaf08285bc7614a048/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f657269636d616e6e2f73657373696f6e7a2e737667)](https://packagist.org/packages/ericmann/sessionz)
====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-sessionz---)

Sessionz is a PHP library for smarter session management in modular applications.

Requirements
------------

[](#requirements)

- PHP 7.4 or newer (tested against 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5)
- [Composer](https://getcomposer.org/)

Installation
------------

[](#installation)

```
composer require ericmann/sessionz
```

Quick Start
-----------

[](#quick-start)

After loading your autoloader, initialize the core session manager and register the handlers you need:

```
require __DIR__ . '/vendor/autoload.php';

EAMann\Sessionz\Manager::initialize()
    ->addHandler( new \EAMann\Sessionz\Handlers\DefaultHandler() )
    ->addHandler( new \EAMann\Sessionz\Handlers\EncryptionHandler( getenv('session_passkey') ) )
    ->addHandler( new \EAMann\Sessionz\Handlers\MemoryHandler() );

session_start();
```

The above example adds, in order:

- The default PHP session handler (which uses files for storage)
- An encryption middleware such that session data will be encrypted at rest on disk
- An in-memory cache to avoid round-trips to the filesystem on read

How Handlers Work
-----------------

[](#how-handlers-work)

The session manager maintains a list of registered "handlers" to which it passes requests from the PHP engine to:

- Read a session
- Write a session
- Create a session store
- Clean up (garbage collect) expired sessions
- Delete a session

Each handler must implement the `Handler` interface so the session manager knows how to work with them.

### Middleware Structure

[](#middleware-structure)

The overall structure of the handler stack is identical to that of a middleware stack in a modern PHP application. You can read more about the general philosophy [on Slim's website](https://www.slimframework.com/docs/v4/concepts/middleware.html).

In general, stack operations will flow from the outside-in, starting by invoking the appropriate operation on the most recently registered handler and walking down the stack to the oldest handler. Each handler has the option to halt execution and return data immediately, or can invoke the passed `$next` callback to continue operation.

Using the quick start example above:

- Requests start in the `MemoryHandler`
- If necessary, they then pass to the `EncryptionHandler`
- Requests always pass from encryption to the `DefaultHandler`
- If necessary, they then pass to the (hidden) `BaseHandler`
- Then everything returns because the base handler doesn't pass anything on

Available Handlers
------------------

[](#available-handlers)

### `DefaultHandler`

[](#defaulthandler)

The default session handler merely exposes PHP's default session implementation to our custom manager. Including this handler will provide otherwise standard PHP session functionality to the project as a whole, but this functionality can be extended by placing other stacks on top.

### `EncryptionHandler`

[](#encryptionhandler)

Sessions stored on disk (the default implementation) or in a separate storage system (Memcache, MySQL, or similar) should be encrypted *at rest*. This handler will automatically encrypt any information passing through it on write and decrypt data on read. It does not store data on its own.

This handler requires a symmetric encryption key when it's instantiated. This key should be an ASCII-safe string generated by [Defuse PHP Encryption](https://github.com/defuse/php-encryption) (a dependency of this library):

```
use Defuse\Crypto\Key;

$rawKey = Key::createNewRandomKey();
$key    = $rawKey->saveToAsciiSafeString();

// Store $key somewhere safe (e.g. an environment variable) and pass it
// back into the EncryptionHandler constructor on every request.
```

### `MemoryHandler`

[](#memoryhandler)

If the final storage system presented to the session manager is remote, reads and writes can take a non-trivial amount of time. Storing session data in memory helps to make the application more performant. Reads will stop at this layer in the stack if the session is found (i.e. the cache is hot) but will flow to the next layer if no session exists. When a session is found in a subsequent layer, this handler will update its cache to make the data available upon the next lookup.

Writes will update the cache and pass through to the next layer in the stack.

### Abstract handlers

[](#abstract-handlers)

The `BaseHandler` class is always instantiated and included at the root of the handler stack by default. This is so that, no matter what handlers you add in to the stack, the session manager will always return a standard, reliable set of information.

The `NoopHandler` class is provided for you to build additional middleware atop a standard interface that "passes through" to the next layer in the stack by default. The `EncryptionHandler`, for example, inherits from this class as it doesn't store or read data, but merely manipulates information before passing it along. Another implementation might be a logging interface to track when sessions are accessed/updated.

Development
-----------

[](#development)

Clone the repository and install dev dependencies:

```
git clone https://github.com/ericmann/sessionz.git
cd sessionz
composer install
```

Run the test suite:

```
composer test
```

Static analysis is provided by [PHPStan](https://phpstan.org/) and runs automatically in CI.

Contributing
------------

[](#contributing)

Issues and pull requests are welcome at . Please ensure new code is covered by tests and that `composer test` passes across the supported PHP matrix before opening a PR.

License
-------

[](#license)

[MIT](LICENSE.md)

Credits
-------

[](#credits)

The middleware implementation is inspired heavily by the request middleware stack presented by [the Slim Framework](https://www.slimframework.com/).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance84

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~571 days

Recently: every ~819 days

Total

7

Last Release

80d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.6

0.5.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/86bb3fa9fcfe57b8d313e527e9e02bde810951b25722b4717b0953a6c8db41b2?d=identicon)[ericmann](/maintainers/ericmann)

---

Top Contributors

[![ericmann](https://avatars.githubusercontent.com/u/605474?v=4)](https://github.com/ericmann "ericmann (32 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![sayful1](https://avatars.githubusercontent.com/u/6873334?v=4)](https://github.com/sayful1 "sayful1 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ericmann-sessionz/health.svg)

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

###  Alternatives

[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)[voku/stringy

A string manipulation library with multibyte support

1863.9M26](/packages/voku-stringy)[wallabag/wallabag

open source self hostable read-it-later web application

12.8k2.2k](/packages/wallabag-wallabag)[paragonie/easy-ecc

Usabiliy Wrapper for mdanter/ecc

47702.5k13](/packages/paragonie-easy-ecc)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

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