PHPackages                             danfsd/php-express-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. danfsd/php-express-session-handler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

danfsd/php-express-session-handler
==================================

Session Handler that talks the same language as your express-session.

11591PHP

Since Oct 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/danfsd/php-express-session-handler)[ Packagist](https://packagist.org/packages/danfsd/php-express-session-handler)[ RSS](/packages/danfsd-php-express-session-handler/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Express Session Handler
=======================

[](#express-session-handler)

This library is meant to work as a Session Handler for PHP that is compatible with [express-session](https://github.com/expressjs/session).

The main motivation for this was the need to share Session between a PHP application and a NodeJS application.

This was inspired on this [gist](https://gist.github.com/mscdex/9507b0d8df42e0aec825) by [mscdex](https://gist.github.com/mscdex), implementing some of its strategies with a `SessionHandler` implementation.

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

[](#requirements)

This library is meant to use the Save Handlers defined on `session.save_handler` directive, the library itself doesn't have any code regarding save handlers.

- **PHP**: `5.6` or greater
- **phpredis** or other Save Handler Extension. (you can install it using `pecl install redis`)
- **php\_serialize** Serialize Handler.

**NOTE: this was tested using [express-session](https://github.com/expressjs/session) with the [connect-redis](https://github.com/tj/connect-redis) Session Store. This is supposed to work with any Session Store that stores it's data as JSON**.

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

[](#installation)

### Composer

[](#composer)

Just run:

```
composer require danfsd/php-express-session-handler

```

Setup
-----

[](#setup)

### Redis

[](#redis)

You can set the following directive on `php.ini` like the following:

```
session.session_name = PHPSESSID
session.save_handler = redis
session.save_path = "tcp://127.0.0.1/?prefix=session:php:"
session.serialize_handler = php_serialize

```

Or you can set it using PHP's `ini_set` function like the following:

```
ini_set("session.session_name", "PHPSESSID");
ini_set("session.save_handler", "redis");
ini_set("session.save_path", "tcp://127.0.0.1/?prefix=session:php:");
ini_set("session.serialize_handler", "php_serialize");
```

Usage
-----

[](#usage)

```
use danfsd\ExpressSessionHandler;

// This is the express-session's secret you defined in your NodeJS application
const SESSION_SECRET = "node.js";

$handler = new ExpressSessionHandler(SESSION_SECRET);

// Setting the Handler
session_set_save_handler($handler, true);

// Starting/Recoverying session
session_start();

// Populates $_SESSION['cookie'] with data that express-session requires
$handler->populateSession();

echo "";
var_dump($_SESSION);
var_dump($_COOKIE);
echo ";"
```

More examples will be disclosed soon.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/07a98c29677b3e97c611d843b111030da02a9ec5a67127e23df1d54bc638defb?d=identicon)[danfsd](/maintainers/danfsd)

---

Top Contributors

[![danfsd](https://avatars.githubusercontent.com/u/4552181?v=4)](https://github.com/danfsd "danfsd (2 commits)")

### Embed Badge

![Health badge](/badges/danfsd-php-express-session-handler/health.svg)

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

###  Alternatives

[craftcms/wp-import

WordPress → Craft CMS content importer

243.9k3](/packages/craftcms-wp-import)

PHPackages © 2026

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