PHPackages                             webwings/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. [Database &amp; ORM](/categories/database)
4. /
5. webwings/mysql-session-handler

ActiveLibrary[Database &amp; ORM](/categories/database)

webwings/mysql-session-handler
==============================

MySQL session handler for Nette Framework with optionally encrypted storage

v3.0.0(5y ago)04391MITPHPPHP &gt;=7.3

Since Dec 4Pushed 5y agoCompare

[ Source](https://github.com/webwingscz/mysql-session-handler)[ Packagist](https://packagist.org/packages/webwings/mysql-session-handler)[ RSS](/packages/webwings-mysql-session-handler/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (11)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/utils](https://github.com/nette/utils) 2.4+
- PHP 7.3+

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

[](#installation)

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

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

Setup
-----

[](#setup)

After installation:

1. Create the table sessions using SQL in [sql/create.sql](sql/create.sql).
2. Register an extension in config.neon:

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

3. Setup DatabaseStorage

```
sessionHandler:
    storage: Webwings\Session\Storage\DibiDatabaseStorage(@dibi.connection, 'sessions')
```

Features
--------

[](#features)

- For security reasons, 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 to add additional columns to the session storage table for example.
- 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 define 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 unecrypted 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) or an existing session (a row us updated). The event is not triggered when just the session timestamp is updated without any change in the session data.

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

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

```

Use it to store for example user id to which the session belongs to.

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) &amp; [Michal Špaček](https://github.com/spaze)) thanks!

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 70.8% 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 ~259 days

Recently: every ~196 days

Total

10

Last Release

1846d ago

Major Versions

v1.2.1 → v2.0.02019-03-03

v2.1.3 → v3.0.02021-04-26

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

v1.2.1PHP &gt;=5.4

v2.0.0PHP &gt;=7.2

v3.0.0PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18418450?v=4)[Webwings s.r.o.](/maintainers/webwingscz)[@webwingscz](https://github.com/webwingscz)

---

Top Contributors

[![spaze](https://avatars.githubusercontent.com/u/1966648?v=4)](https://github.com/spaze "spaze (17 commits)")[![juradee](https://avatars.githubusercontent.com/u/4532277?v=4)](https://github.com/juradee "juradee (4 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)")

### Embed Badge

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

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

###  Alternatives

[nette/caching

⏱ Nette Caching: library with easy-to-use API and many cache backends.

43518.6M368](/packages/nette-caching)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2592.8M263](/packages/ssch-typo3-rector)[ublaboo/datagrid

DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc

2971.9M23](/packages/ublaboo-datagrid)[kdyby/doctrine

Doctrine integration into Nette Framework

1091.0M86](/packages/kdyby-doctrine)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

134391.5k12](/packages/rector-rector-src)[contributte/monolog

Monolog integration into Nette Framework

231.9M7](/packages/contributte-monolog)

PHPackages © 2026

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