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

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

compwright/php-session
======================

Standalone session implementation that does not rely on the PHP session module or the $\_SESSION global, ideal for ReactPHP applications

v3.3.0(1y ago)189.4k—8.3%3MITPHPPHP ^8.0

Since Aug 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/compwright/php-session)[ Packagist](https://packagist.org/packages/compwright/php-session)[ Docs](https://github.com/compwright/php-session)[ Fund](https://www.buymeacoffee.com/compwright)[ GitHub Sponsors](https://github.com/sponsors/compwright)[ RSS](/packages/compwright-php-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (19)Versions (24)Used By (0)

Compwright\\PhpSession
======================

[](#compwrightphpsession)

A PHP session implementation that is single-process safe, compatible with PSR-7 and PSR-15, and does not rely on global variables ($\_SESSION, $\_COOKIE, etc).

This implementation is patterned after the built-in PHP session library, but is not a drop-in replacement for it. This library differs from the PHP session library in the following ways:

- Requires PHP 8+
- Fully object-oriented
- Strict mode is always on and cannot be disabled
- Auto-start and auto-shutdown are not supported
- Reading/writing cookie and cache headers is handled in middleware (included)
- Handlers implement the built-in PHP SessionHandlerInterface, but the PHP SessionHandler class will not work because it depends internally on the PHP session extension
- Session data is accessed using a Session object, not via $\_SESSION

This library is ideal for single-process event loop-driven applications, using servers like [ReactPHP](https://reactphp.org).

Supported Features
------------------

[](#supported-features)

- [Array or Object Access](features/access.feature)
- [Collision-Proof Secure ID Generation](features/id.feature)
- [Data Persistance](features/persistence.feature)
- [ID Regeneration](features/regeneration.feature)
- [Lockless Concurrency](features/concurrency.feature)
- [Garbage Collection](features/gc.feature)

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

[](#installation)

```
composer require compwright/php-session

```

Examples
--------

[](#examples)

### Slim Framework

[](#slim-framework)

See [tests/integration/server/App](tests/integration/server/App)

To run with PHP Development Server:

```
$ composer run-script start-php

```

### Basic Usage

[](#basic-usage)

```
$sessionFactory = new Compwright\PhpSession\Factory();

$manager = $sessionFactory->psr16Session(
    /**
     * @param Psr\SimpleCache\CacheInterface
     */
    $cache,

    /**
     * @param array|Compwright\PhpSession\Config
     */
    [
        'name' => 'my_app',
        'sid_length' => 48,
        'sid_bits_per_character' => 5,
    ]
);

// Start the session
$manager->id($sid); // Read $sid from request
$started = $manager->start();
if ($started === false) {
    throw new RuntimeException("The session failed to start");
}

// Read/write the current session
$session = $manager->getCurrentSession();
$session["foo"] = "bar";
unset($session["bar"]);

// Save and close the session
$ended = $manager->write_close();
if ($ended === false) {
    throw new RuntimeException("The session failed to close properly, data may have been lost");
}
```

License
-------

[](#license)

[MIT License](LICENSE)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance41

Moderate activity, may be stable

Popularity34

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~59 days

Recently: every ~186 days

Total

22

Last Release

489d ago

Major Versions

1.2.4 → 2.0.02022-12-19

2.0.0 → v3.0.02022-12-23

1.3.0 → v3.1.12022-12-29

1.x-dev → v3.1.22023-02-14

PHP version history (3 changes)1.0.0PHP ^7.4 || ^8.0

2.0.0PHP ^8.0 || ^8.1 || ^8.2

v3.3.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/138688?v=4)[Jonathon Hill](/maintainers/compwright)[@compwright](https://github.com/compwright)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![compwright](https://avatars.githubusercontent.com/u/138688?v=4)](https://github.com/compwright "compwright (7 commits)")[![yani](https://avatars.githubusercontent.com/u/6956790?v=4)](https://github.com/yani "yani (4 commits)")[![FabienYt](https://avatars.githubusercontent.com/u/101272997?v=4)](https://github.com/FabienYt "FabienYt (1 commits)")

---

Tags

psr-15psr-7react-phpreactphpsessionsswoolemiddlewarepsr7reactphpsessionstandalonepsr15psr16

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/compwright-php-session/health.svg)

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

###  Alternatives

[league/route

Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

6633.1M115](/packages/league-route)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[cakephp/authentication

Authentication plugin for CakePHP

1153.6M67](/packages/cakephp-authentication)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[yiisoft/yii-middleware

Yii Middleware

21151.3k1](/packages/yiisoft-yii-middleware)[phps-cans/psr7-middleware-graphql

This package contains a http-interop middleware implementation to handle graphql request

1528.7k](/packages/phps-cans-psr7-middleware-graphql)

PHPackages © 2026

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