PHPackages                             sylae/doctrine-dbal-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. sylae/doctrine-dbal-session-handler

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

sylae/doctrine-dbal-session-handler
===================================

SessionHandlerInterface implementation using doctrine/dbal

v0.2(3y ago)032[1 PRs](https://github.com/sylae/doctrine-dbal-session-handler/pulls)MITPHP

Since Aug 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sylae/doctrine-dbal-session-handler)[ Packagist](https://packagist.org/packages/sylae/doctrine-dbal-session-handler)[ Fund](https://paypal.me/MisfitMaid)[ Patreon](https://www.patreon.com/MisfitMaid)[ RSS](/packages/sylae-doctrine-dbal-session-handler/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

This provides a single class, `\Doctrine\DBAL\DBALSessionHandler`, which allows you to toss your session onto an SQL database with as little effort as possible.

As of now, it's only tested on mysql8, but it should work fine for anything really? The only sticking point is a REPLACE INTO command, but that can easily be pull-requested :p

Example of use:

```
$db = \Doctrine\DBAL\DriverManager::getConnection(/* or whatever */);

$sessionHandler = new \Doctrine\DBAL\DBALSessionHandler($db);
$sessionHandler->setSessionTable("whatever"); // defaults to "sessions" if not called
session_set_save_handler($sessionHandler, true);
```

By default, we also store the IP and user agent of these sessions alongside the actual session data. In addition, you can provide a user ID by passing along a callable. This is to facilite allowing the user to see what sessions they have active on their account, and revoking them through your site.

```
$sessionHandler->setUserIDHandler(function (): ?int {
    return $this->user->id ?? null; // or wherever you keep your user ID.
});
```

Right now it doesnt do any bougie-ass table management for you, so you have to do a little bit of sql:

```
/* minimum you can get away with */
CREATE TABLE `sessions`
(
    `idSession` char(64) NOT NULL,
    `data`      text,
    `ip`        binary(16)      DEFAULT NULL,
    `userAgent` varchar(255)    DEFAULT NULL,
    `idUser`    bigint unsigned DEFAULT NULL, /* change size as needed, this is just what i use */
    PRIMARY KEY (`idSession`),
);

/* what i use */
CREATE TABLE `sessions`
(
    `idSession` char(64) NOT NULL,
    `updated`   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `created`   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `data`      text,
    `ip`        binary(16)        DEFAULT NULL,
    `userAgent` varchar(255)      DEFAULT NULL,
    `idUser`    bigint unsigned   DEFAULT NULL,
    PRIMARY KEY (`idSession`),
    KEY `sessions_ibfk_1` (`idUser`),
    CONSTRAINT `sessions_ibfk_1` FOREIGN KEY (`idUser`) REFERENCES `users` (`idUser`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci;
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~23 days

Total

2

Last Release

1394d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2791628?v=4)[MisfitMaid](/maintainers/sylae)[@sylae](https://github.com/sylae)

---

Top Contributors

[![sylae](https://avatars.githubusercontent.com/u/2791628?v=4)](https://github.com/sylae "sylae (6 commits)")

---

Tags

doctrinedoctrine-dbalphpphp-library

### Embed Badge

![Health badge](/badges/sylae-doctrine-dbal-session-handler/health.svg)

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

###  Alternatives

[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4585.8M4](/packages/martin-georgiev-postgresql-for-doctrine)[flow-php/doctrine-dbal-bulk

Bulk inserts and updates for Doctrine DBAL

14385.8k4](/packages/flow-php-doctrine-dbal-bulk)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)

PHPackages © 2026

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