PHPackages                             horde/sessionhandler - 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. horde/sessionhandler

ActiveHorde-library[Utility &amp; Helpers](/categories/utility)

horde/sessionhandler
====================

Session handler library

v3.0.0(3d ago)23.8k↑14.6%5[1 issues](https://github.com/horde/SessionHandler/issues)1LGPL-2.1-onlyPHPPHP ^8

Since Aug 27Pushed 3d ago5 watchersCompare

[ Source](https://github.com/horde/SessionHandler)[ Packagist](https://packagist.org/packages/horde/sessionhandler)[ Docs](https://www.horde.org/libraries/Horde_SessionHandler)[ RSS](/packages/horde-sessionhandler/feed)WikiDiscussions FRAMEWORK\_6\_0 Synced yesterday

READMEChangelog (6)Dependencies (21)Versions (27)Used By (1)

Horde\\SessionHandler
=====================

[](#hordesessionhandler)

Session management with typed objects, capability-detected backends, and no framework opinions.

This library is right for people who like Symfony's rigor, Aura's cleanliness, all my own bugs and PSR-style composability but don't want a framework in their session layer.

Install
-------

[](#install)

```
composer require horde/sessionhandler

```

Quick start
-----------

[](#quick-start)

```
use Horde\SessionHandler\SessionHandler;
use Horde\SessionHandler\Storage\FileBackend;

$handler = new SessionHandler(
    backend: new FileBackend('/var/sessions'),
);

// Create, read, write, done.
$session = $handler->create();
$session->set('user', 'alice');
$handler->save($session);

// Later...
$session = $handler->load($session->getId());
echo $session->get('user'); // alice
```

Or register it as PHP's native handler and keep using `$_SESSION`:

```
session_set_save_handler($handler, true);
session_start();
$_SESSION['user'] = 'alice';
```

Architecture
------------

[](#architecture)

The library is built around three ideas:

**Typed value objects.** Session IDs are `SessionId`, not strings that might be empty. Payloads are `SerializedSessionPayload`, not strings that might be JSON or might be PHP-serialized. Metadata is `SessionMetadata` with `DateTimeImmutable` fields, not integer timestamps cast from database columns.

**Capability interfaces.** A backend declares what it can do through the interfaces it implements. The core asks the type system, not a method that returns `true`:

InterfaceWhat it means`SessionStorageBackend`load / save / delete (required)`IterableSessionBackend`can list active sessions`SessionMetadataBackend`can report created/modified/expires times`AdministrativeSessionBackend`can force-expire a session`LockingSessionBackend`can acquire/release per-session locksThe orchestrator (`SessionHandler`) checks `instanceof` before calling capability methods and throws `CapabilityException` when the backend does not support the requested operation.

**PSR composability.** The handler takes an optional PSR-14 `EventDispatcherInterface` for lifecycle events and a PSR-20 `ClockInterface` for deterministic time in tests.

Backends
--------

[](#backends)

ClassCapabilitiesRequires`FileBackend`all fivewritable directory`SqlBackend`storage, iteration, metadata, admin`horde/db``HashtableBackend`storage, iteration\*, admin`horde/hashtable``StackBackend`storage onlytwo or more backends`ExternalBackend`storage onlythree closures`BuiltinBackend`storage onlyPHP's default handler\*HashtableBackend iteration requires `track: true` at construction.

### Constructors

[](#constructors)

```
new FileBackend(string $path)
new SqlBackend(Horde\Db\Adapter $db, string $table = 'horde_sessionhandler')
new HashtableBackend(Horde_HashTable_Base & Horde_HashTable_Lock $ht, bool $track = false)
new StackBackend(SessionStorageBackend ...$backends)   // last is master
new ExternalBackend(Closure $read, Closure $write, Closure $delete)
new BuiltinBackend(string $path = '')
```

The Session object
------------------

[](#the-session-object)

`Session` is an interface. The default implementation (`DefaultSession`) is an in-memory key-value store with dirty tracking:

```
$session->set('cart', []);       // marks dirty
$session->get('cart');           // []
$session->has('cart');           // true
$session->remove('cart');        // marks dirty
$session->keys();                // ['remaining', 'keys']
$session->isDirty();             // true
```

`SessionHandler::save()` is a no-op when `isDirty()` returns false.

Events
------

[](#events)

When an `EventDispatcherInterface` is provided, the handler dispatches:

- `SessionCreated` -- after `create()`
- `SessionLoaded` -- after `load()`
- `SessionSaved` -- after `save()`
- `SessionDestroyed` -- after `destroySession()`
- `SessionExpired` -- after `expire()`
- `SessionIdRegenerated` -- after `regenerate()`, carries both old and new IDs

Two informational event classes (`BackendError`, `LockFailed`) exist for application-level error monitoring.

Extending
---------

[](#extending)

Custom backends implement `SessionStorageBackend` and optionally the capability interfaces they support. Custom serializers implement `SessionSerializer`. Custom session objects implement `Session` and come with a matching `SessionFactory`.

The Horde application framework provides `HordeSession` (in `horde/core`, namespace `Horde\Core\Session`) which extends `DefaultSession` with scoped key access, authentication metadata via `SessionMetaInterface`, and transparent per-key encryption via `EncryptedValuesInterface`. `HordeSession` stores data in the same two-level `$data[$app][$name]`structure as PHP's native `$_SESSION`, so sessions written by the legacy handler are readable without conversion.

A `NativePhpSessionSerializer` bridges sessions stored through `$_SESSION`with the object API.

See [doc/EXTENDING.md](doc/EXTENDING.md) for the full guide.

Upgrading from the legacy Horde\_SessionHandler
-----------------------------------------------

[](#upgrading-from-the-legacy-horde_sessionhandler)

The `lib/` tree ships alongside `src/` for backward compatibility. Both autoload paths are active in `composer.json`. Existing code using `Horde_SessionHandler` and `Horde_SessionHandler_Storage_*` continues to work without changes.

New code should use the `Horde\SessionHandler` namespace. The storage format is wire-compatible for file and SQL backends, but the serialization path differs between the native `$_SESSION` interface and the explicit object API -- do not mix both for the same session.

See [doc/UPGRADING.md](doc/UPGRADING.md) for the detailed migration guide.

License
-------

[](#license)

LGPL-2.1-only. See [LICENSE](LICENSE).

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance89

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community31

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 59.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 ~293 days

Recently: every ~19 days

Total

17

Last Release

3d ago

Major Versions

2.3.0 → 3.0.0alpha22021-02-24

PHP version history (7 changes)2.2.4PHP &gt;=5.3.0

2.2.5PHP &gt;=5.3.0,&lt;=6.0.0alpha1

2.2.7PHP &gt;=5.3.0,&lt;=8.0.0alpha1

2.3.0PHP ^5.3 || ^7

3.0.0alpha2PHP ^7

v3.0.0alpha3PHP ^7.4 || ^8

v3.0.0beta1PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/c943a083635c28520599075eaea7ede2d743b7697b76e84d6bdc37e52cc8249b?d=identicon)[yunosh](/maintainers/yunosh)

![](https://www.gravatar.com/avatar/c931cd02664859360478593450d6c473a05bb12b209dfacfc534cd13257cc7ef?d=identicon)[ralflang](/maintainers/ralflang)

![](https://www.gravatar.com/avatar/e4f6c6771993db2ed500959b42353f6cf6a2ca0406d9617f7ae680f4504faa4a?d=identicon)[horde](/maintainers/horde)

![](https://www.gravatar.com/avatar/a7767adb66b45f2f05bcd44d49bc4e67efacd9ce05b161ce2d481d5dd6af025c?d=identicon)[mrubinsk](/maintainers/mrubinsk)

![](https://www.gravatar.com/avatar/816e2b926f25f8cd2939054c7a7173011b4303d690e25ab61bf33cf8c7cf71ae?d=identicon)[tdannhauer](/maintainers/tdannhauer)

---

Top Contributors

[![yunosh](https://avatars.githubusercontent.com/u/379318?v=4)](https://github.com/yunosh "yunosh (177 commits)")[![slusarz](https://avatars.githubusercontent.com/u/381003?v=4)](https://github.com/slusarz "slusarz (71 commits)")[![ralflang](https://avatars.githubusercontent.com/u/646976?v=4)](https://github.com/ralflang "ralflang (28 commits)")[![mrubinsk](https://avatars.githubusercontent.com/u/66822?v=4)](https://github.com/mrubinsk "mrubinsk (14 commits)")[![bklang](https://avatars.githubusercontent.com/u/167131?v=4)](https://github.com/bklang "bklang (3 commits)")[![thomasjfox](https://avatars.githubusercontent.com/u/1146758?v=4)](https://github.com/thomasjfox "thomasjfox (1 commits)")[![wrobel](https://avatars.githubusercontent.com/u/10232?v=4)](https://github.com/wrobel "wrobel (1 commits)")[![KimTheFirst](https://avatars.githubusercontent.com/u/15432758?v=4)](https://github.com/KimTheFirst "KimTheFirst (1 commits)")[![selsky](https://avatars.githubusercontent.com/u/380337?v=4)](https://github.com/selsky "selsky (1 commits)")[![TDannhauer](https://avatars.githubusercontent.com/u/6716033?v=4)](https://github.com/TDannhauer "TDannhauer (1 commits)")

---

Tags

sessionssessionless\_sessions

### Embed Badge

![Health badge](/badges/horde-sessionhandler/health.svg)

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

###  Alternatives

[horde/horde

Horde base application

583.0k70](/packages/horde-horde)[horde/kronolith

Calendar and scheduling application

101.5k4](/packages/horde-kronolith)[horde/imp

Webmail application

261.3k](/packages/horde-imp)[horde/imap_client

IMAP client library

275.5k19](/packages/horde-imap-client)

PHPackages © 2026

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