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.3.1(8y ago)585.0k7[1 PRs](https://github.com/ericmann/sessionz/pulls)2MITPHPPHP &gt;=5.6CI failing

Since Nov 26Pushed 3y ago4 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (6)Used By (2)

PHP Sessionz [![Build Status](https://camo.githubusercontent.com/0c4ae28debbace2b13f7c818a03b133f77e9d839b3faa5a7e21765042bc7c67d/68747470733a2f2f7472617669732d63692e6f72672f657269636d616e6e2f73657373696f6e7a2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ericmann/sessionz) [![Coverage Status](https://camo.githubusercontent.com/a825e6ba56b03be8e0cd566155582966f0a5693cc0af3f8cd4716cf0069d065c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f657269636d616e6e2f73657373696f6e7a2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ericmann/sessionz?branch=master) [![CI](https://github.com/ericmann/sessionz/actions/workflows/ci.yml/badge.svg)](https://github.com/ericmann/sessionz/actions/workflows/ci.yml)
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-sessionz---)

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

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

[](#quick-start)

Use [Composer](https://getcomposer.org/) to add `ericmann/sessionz` to your project. Then, after loading all of your dependencies, initialize the core session manager and add the handlers you need to your stack.

```
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/concepts/middleware.html#how-does-middleware-work).

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, 32 bytes in length. You can easily use [Defuse PHP Encryption](https://github.com/defuse/php-encryption) (a dependency of this library) to generate a new key:

```
$rawKey = Defuse\Crypto\Key::createNewRandomKey();
$key = $rawKey->saveToAsciiSafeString();
```

### `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.

Credits
-------

[](#credits)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.7% 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 ~104 days

Total

5

Last Release

3044d ago

### 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 (29 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

[wallabag/wallabag

open source self hostable read-it-later web application

12.6k2.2k](/packages/wallabag-wallabag)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)[paragonie/easy-ecc

Usabiliy Wrapper for mdanter/ecc

46617.1k10](/packages/paragonie-easy-ecc)[kunstmaan/utilities-bundle

The KunstmaanUtilitiesBundle makes your life easier by providing a couple of small but usefull helper services you can use and re-use in your applications. We already implemented an easy to use cipher service and a shell helper service for you but feel free to send in a pull request with your additions. The shell helper allows you to run apps in the background, see if a process is running and has a method to kill a running process. The cipher service allow you to encode and decode strings using the Rijndael 256 cipher

13150.5k6](/packages/kunstmaan-utilities-bundle)[harmonic/laravel-envcoder

:description

414.1k](/packages/harmonic-laravel-envcoder)

PHPackages © 2026

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