PHPackages                             wyrihaximus/react-http-middleware-session - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. wyrihaximus/react-http-middleware-session

ActiveLibrary[HTTP &amp; Networking](/categories/http)

wyrihaximus/react-http-middleware-session
=========================================

react/http middleware that takes care of session handling

4.1.0(5y ago)910.0k4[2 issues](https://github.com/WyriHaximus/reactphp-http-middleware-session/issues)[2 PRs](https://github.com/WyriHaximus/reactphp-http-middleware-session/pulls)3MITMakefilePHP ^8 || ^7.4CI passing

Since Apr 7Pushed 2d ago2 watchersCompare

[ Source](https://github.com/WyriHaximus/reactphp-http-middleware-session)[ Packagist](https://packagist.org/packages/wyrihaximus/react-http-middleware-session)[ GitHub Sponsors](https://github.com/WyriHaximus)[ RSS](/packages/wyrihaximus-react-http-middleware-session/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (7)Versions (18)Used By (3)

Middleware that takes care of session handling
==============================================

[](#middleware-that-takes-care-of-session-handling)

[![Continuous Integration](https://github.com/wyrihaximus/php-http-middleware-session/workflows/Continuous%20Integration/badge.svg)](https://github.com/wyrihaximus/php-http-middleware-session/workflows/Continuous%20Integration/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/070eae797e4546029a61dd16103fe94edf8a873cd9a97c09fa193055a18d6b98/68747470733a2f2f706f7365722e707567782e6f72672f77797269686178696d75732f687474702d6d6964646c65776172652d73657373696f6e2f762f737461626c652e706e67)](https://packagist.org/packages/wyrihaximus/http-middleware-session)[![Total Downloads](https://camo.githubusercontent.com/7a387f9b54808a841368cf0fe8cc51a6ffb025f37f3fccc79c00bcbc68b1ac94/68747470733a2f2f706f7365722e707567782e6f72672f77797269686178696d75732f687474702d6d6964646c65776172652d73657373696f6e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/wyrihaximus/http-middleware-session/stats)[![Code Coverage](https://camo.githubusercontent.com/85d7c723683c19fe97129c37e46a320bd6d548585da3276a8086605754788d3a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f57797269486178696d75732f7068702d687474702d6d6964646c65776172652d73657373696f6e2f62616467652e7376673f6272616e63686d6173746572)](https://coveralls.io/github/WyriHaximus/php-http-middleware-session?branch=master)[![Type Coverage](https://camo.githubusercontent.com/487e1033331fefe53546f99bf12b02a22a66dc14da256820065abc896963d485/68747470733a2f2f73686570686572642e6465762f6769746875622f57797269486178696d75732f7068702d687474702d6d6964646c65776172652d73657373696f6e2f636f7665726167652e737667)](https://shepherd.dev/github/WyriHaximus/php-http-middleware-session)[![License](https://camo.githubusercontent.com/c5f35f493fc3f9bd4f378e1918bea994b40feb0c68f0ad246f486832bd540659/68747470733a2f2f706f7365722e707567782e6f72672f77797269686178696d75732f687474702d6d6964646c65776172652d73657373696f6e2f6c6963656e73652e706e67)](https://packagist.org/packages/wyrihaximus/http-middleware-session)

Install
=======

[](#install)

To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.

```
composer require wyrihaximus/react-http-middleware-session

```

This middleware takes care of session handling. It uses [`react/cache`](https://reactphp.org/cache/) for storage or any cache handler implementing [`React\Cache\CacheInterface`](https://github.com/reactphp/react/wiki/Users#cache-implementations).

Usage
=====

[](#usage)

```
$server = new Server(
    $loop,
    /** Other Middleware */
    new SessionMiddleware(
        'CookieName',
        $cache, // Instance implementing React\Cache\CacheInterface
        [ // Optional array with cookie settings, order matters
            0, // expiresAt, int, default
            '', // path, string, default
            '', // domain, string, default
            false, // secure, bool, default
            false // httpOnly, bool, default
        ],
    ),
    /** Other Middleware */
    function (ServerRequestInterface $request) {
        $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE_NAME);

        // Overwrite session contents, the details of changing specific keys is up to you
        $session->setContents([
            'foo' => 'bar',
        ]);

        // Get session contents
        var_export($session->getContents()); // Prints something like: ['foo' = 'bar']

        return new Response();
    }
);
```

Response cache
==============

[](#response-cache)

Using this middleware together with [`wyrihaximus/react-http-middleware-response-cache`](https://github.com/WyriHaximus/reactphp-http-middleware-response-cache) then please take a look at [`wyrihaximus/react-http-middleware-response-cache-session-cache-configuration`](https://github.com/WyriHaximus/reactphp-http-middleware-response-cache-session-cache-configuration) to ensure you don't cache responses from users with active sessions.

To/From array
-------------

[](#tofrom-array)

In case you need to pass a session into a child process it has `toArray` and `fromArray` methods:

```
$array = $session->toArray();
// Transfer to child process
$session = (new Session('', [], new RandomBytes()))->fromArray($array);
// The same can be done transferring changes back to the parent
```

License
=======

[](#license)

The MIT License (MIT)

Copyright (c) 2026 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance61

Regular maintenance activity

Popularity30

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 67.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 ~153 days

Recently: every ~231 days

Total

8

Last Release

1935d ago

Major Versions

1.2.0 → 2.0.02018-09-03

2.1.0 → 3.0.02019-07-12

3.0.0 → 4.0.02020-09-12

PHP version history (4 changes)1.0.0PHP ^7.0

2.0.0PHP ^7.2

3.0.0PHP ^7.3

4.1.0PHP ^8 || ^7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

---

Top Contributors

[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (115 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (30 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (18 commits)")[![renovate-runner[bot]](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/renovate-runner[bot] "renovate-runner[bot] (4 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (3 commits)")[![pavarnos](https://avatars.githubusercontent.com/u/589595?v=4)](https://github.com/pavarnos "pavarnos (1 commits)")

---

Tags

cookiecookieshacktoberfesthttpmiddlewarephpphp7reactphpsession

### Embed Badge

![Health badge](/badges/wyrihaximus-react-http-middleware-session/health.svg)

```
[![Health](https://phpackages.com/badges/wyrihaximus-react-http-middleware-session/health.svg)](https://phpackages.com/packages/wyrihaximus-react-http-middleware-session)
```

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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