PHPackages                             acfo/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. acfo/session

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

acfo/session
============

Simple session class with strict typing, read only and lazy load support

1.0.0(8y ago)0152MITPHPPHP &gt;=7.1.0

Since Sep 14Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (2)Used By (0)

\#Session

Simple strict typed session class which supports read only (read\_and\_close) and lazy loading. This package also provides a useful PSR-7 compatible middleware, e.g. for the Slim Framework 3.x, for starting a session.

\###Installation

```
composer require acfo/session
```

\###Usage

Add the session class an middleware to your dependency injection container (e.g. Pimple):

```
$container[\Acfo\Session\Session::class] = function () {
    return new \Acfo\Session\SessionImpl();
};

$container[\Acfo\Session\Middleware\Slim3\SessionMiddleware] = function ($container) {
    return new \Acfo\Session\Middleware\Slim3\SessionMiddleware(
        $container->get(\Acfo\Session\Session::class)
    );
};
```

Add middleware (e.g. Slim 3.x):

```
$app->add(\Acfo\Session\Middleware\Slim3\SessionMiddleware::class);
```

This setup will allow read and write operations and not start the session before it is actually used, e.g.:

```
$session = $container->get(\Acfo\Session\Session::class);

$value = $session->get('key'); // lazy load: first access will invoke start_session

$session->set('key', 1234);

$session->regenerate();

$session->delete('key');

$session->deleteAll();

$session->close(); // call close if you want to end a read/write session as soon as possible.

```

\###Advanced usage

The session class supports starting the session with the read\_and\_close flag introduced with PHP 7.0. This feature can help keep the time a session is locked for a specific user to the necessary minimum. This is especially useful for asynchronous web applications which generally do not write data in a GET-Request.

To specify which requests only need read access to the session data, pass a list of objects implementing the ReadOnlySessionStrategy interface as a parameter of the the middleware constructor, e.g.:

```
class GetRequestReadOnlySessionStrategy implements ReadOnlySessionStrategy
{
    public function isReadOnly(ServerRequestInterface $request): bool
    {
        return $request->getMethod() == 'GET';
    }
}

$container[\Acfo\Session\Middleware\Slim3\SessionMiddleware] = function ($container) {
    $readOnlySessionStrategies = [
        new GetRequestReadOnlySessionStrategy()
    ];

    return new \Acfo\Session\Middleware\Slim3\SessionMiddleware(
        $container->get(\Acfo\Session\Session::class),
        $readOnlySessionStrategies
    );
};

$app->add(\Acfo\Session\Middleware\Slim3\SessionMiddleware::class);
```

The default settings for sessions are suitable for most applications. Should you need to adjust a setting, the most efficient way would be to edit the php.ini file. If you cannot or do not want to edit the php.ini file you can pass a list of settings to the SessionMiddleware.

```
$settings = \Acfo\Session\Middleware\Slim3\SessionMiddleware::RECOMMENDED_SETTINGS;

$container[\Acfo\Session\Middleware\Slim3\SessionMiddleware] = function ($container) {
    $settings = \Acfo\Session\Middleware\Slim3\SessionMiddleware::RECOMMENDED_SETTINGS;

    return new \Acfo\Session\Middleware\Slim3\SessionMiddleware(
        $container->get(\Acfo\Session\Session::class),
        null,
        $settings
    );
};

$app->add(\Acfo\Session\Middleware\Slim3\SessionMiddleware::class);
```

Enjoy!

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfe2c32ecf03dbc493366c1147b7cb53cfe350cc643af9a37fa925d1043ac5a8?d=identicon)[acfo](/maintainers/acfo)

---

Top Contributors

[![andrewcforster](https://avatars.githubusercontent.com/u/63876213?v=4)](https://github.com/andrewcforster "andrewcforster (7 commits)")

---

Tags

sessionRead onlystrictlazy loadlazy-initread\_and\_close

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233961.5k16](/packages/bryanjhv-slim-session)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)[plasticbrain/php-flash-messages

A modern take on PHP session-based flash messages

184229.6k8](/packages/plasticbrain-php-flash-messages)[rappasoft/lockout

Put your Laravel application into read-only mode.

96280.4k2](/packages/rappasoft-lockout)[vcian/pulse-active-sessions

A Laravel Pulse card to show active user session.

11469.2k](/packages/vcian-pulse-active-sessions)[magepal/magento2-cataloglazyload

Improve the load time of your Magento 2 categories pages by loading your images on demand with our Lazy Load Extension

5563.9k](/packages/magepal-magento2-cataloglazyload)

PHPackages © 2026

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