PHPackages                             spaze/mysql-session-handler - 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. spaze/mysql-session-handler

ActiveLibrary

spaze/mysql-session-handler
===========================

MySQL session handler for Nette Framework with optionally encrypted storage

v3.2.2(5mo ago)45.1k↓25%4MITPHPPHP ^8.2CI passing

Since Dec 4Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/spaze/mysql-session-handler)[ Packagist](https://packagist.org/packages/spaze/mysql-session-handler)[ RSS](/packages/spaze-mysql-session-handler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (20)Used By (0)

MySQL Session handler
=====================

[](#mysql-session-handler)

Custom PHP session handler for [Nette Framework](http://nette.org/) that uses MySQL database for storage.

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

[](#requirements)

- [nette/database](https://github.com/nette/database) 3.2+
- [nette/di](https://github.com/nette/di) 3.2+
- PHP 8.2+

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

[](#installation)

The preferred way to install spaze/mysql-session-handler is by using [Composer](http://getcomposer.org/):

```
$ composer require spaze/mysql-session-handler
```

Setup
-----

[](#setup)

After installation:

1. Create a table named `sessions` using SQL in [sql/create.sql](sql/create.sql). The name of the table can be changed in the configuration using the `tableName` key, like this:

```
sessionHandler:
    tableName: sessions_table
```

2. Register the extension in your configuration file (e.g. `config.neon`):

```
	extensions:
		sessionHandler: Spaze\Session\DI\MysqlSessionHandlerExtension
```

Features
--------

[](#features)

- For security reasons, the session id is stored in the database as an SHA-256 hash.
- Supports encrypted session storage via [spaze/encryption](https://github.com/spaze/encryption) which uses [paragonie/halite](https://github.com/paragonie/halite) which uses [Sodium](https://php.net/sodium).
- Events that allow you, for example, to add additional columns to the session storage table.
- Multi-master replication-friendly (tested in master-master row-based replication setup).

Encrypted session storage
-------------------------

[](#encrypted-session-storage)

Follow the guide at [spaze/encryption](https://github.com/spaze/encryption#usage-in-nette-framework) to create and configure a new encryption key.

Define a new service:

```
sessionEncryption: \Spaze\Encryption\Symmetric\StaticKey('session', %encryption.keys%, %encryption.activeKeyIds%)

```

Add the new encryption service to the session handler:

```
sessionHandler:
    encryptionService: @sessionEncryption

```

Migration from unencrypted to encrypted session storage is not (yet?) supported.

Events
------

[](#events)

### `onBeforeDataWrite`

[](#onbeforedatawrite)

The event occurs before session data is written to the session table, both for a new session (when a new row is inserted) and for an existing session (when a row is updated), even if there is no change in the session data.

Additional columns
------------------

[](#additional-columns)

You can add a new column to the session table by calling `setAdditionalData()` in the event handler:

```
setAdditionalData(string $key, $value): void

```

Use it to store, for example, the user id the session belongs to. See for example [this code](https://github.com/spaze/michalspacek.cz/blob/fbd438e8f4c1da658a88bc8c3bf5af59fcd063e6/app/src/Application/WebApplication.php#L42-L50) which uses the `Nette\Security\User::onLoggedIn` handler to do that.

Credits
-------

[](#credits)

This is heavily based on [MySQL Session handler](https://github.com/pematon/mysql-session-handler) by [Pematon](https://github.com/orgs/pematon/people) ([Marián Černý](https://github.com/mariancerny) &amp; [Peter Knut](https://github.com/peterpp)), thanks!

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance70

Regular maintenance activity

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 96.3% 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 ~222 days

Recently: every ~168 days

Total

19

Last Release

176d ago

Major Versions

v1.2.1 → v2.0.02019-03-03

v2.3.3 → v3.0.02024-01-19

PHP version history (6 changes)v1.0.0PHP &gt;=5.3

v1.2.1PHP &gt;=5.4

v2.0.0PHP &gt;=7.2

v2.2.0PHP ^7.4 || ^8.0

v2.3.0PHP ^8.1

v3.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6777bd445610e6e458e4d41bdefa3070d2ed4e068323362353b061b15e9ff81b?d=identicon)[spaze](/maintainers/spaze)

---

Top Contributors

[![spaze](https://avatars.githubusercontent.com/u/1966648?v=4)](https://github.com/spaze "spaze (77 commits)")[![peterpp](https://avatars.githubusercontent.com/u/1448883?v=4)](https://github.com/peterpp "peterpp (2 commits)")[![mariancerny](https://avatars.githubusercontent.com/u/1448896?v=4)](https://github.com/mariancerny "mariancerny (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spaze-mysql-session-handler/health.svg)

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

###  Alternatives

[nette/nette

👪 Nette Framework - innovative framework for fast and easy development of secured web applications in PHP (metapackage)

1.6k2.8M335](/packages/nette-nette)[nette/web-project

Nette: Standard Web Project

10991.8k](/packages/nette-web-project)[brandembassy/slim-nette-extension

19190.2k](/packages/brandembassy-slim-nette-extension)

PHPackages © 2026

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