PHPackages                             koded/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. [Caching](/categories/caching)
4. /
5. koded/session

ActiveLibrary[Caching](/categories/caching)

koded/session
=============

A session library with custom handlers and php.ini support

1.1.0(6y ago)23141BSD-3-ClausePHPPHP ~7.3CI failing

Since May 21Pushed 10mo ago2 watchersCompare

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

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

Koded Session
=============

[](#koded-session)

[![Latest Stable Version](https://camo.githubusercontent.com/3faeaf179dd39fcf00545cf1169780518846f2a03150bdc87a95c049cf21a99b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6f6465642f73657373696f6e2e737667)](https://packagist.org/packages/koded/session)[![Build Status](https://camo.githubusercontent.com/7fe2dce58508eef1217ffc49d0a0a2d56e9dfe586d8e7d4b58cee7cc18094818/68747470733a2f2f7472617669732d63692e6f72672f6b6f6465647068702f73657373696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kodedphp/session)[![Code Coverage](https://camo.githubusercontent.com/9b2d2d308aae729751baf950805a417f9431d1d1db0319e2ded5790e19f4ae48/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6465647068702f73657373696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kodedphp/session/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1612ebb47e2ced27c3098be3267aa5883a6079ab0cb031eb5322755ca7dfb6aa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6465647068702f73657373696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kodedphp/container/?branch=master)[![Minimum PHP Version](https://camo.githubusercontent.com/eed4d5cf01364b115489810f47ed4b33191d997e7ab4014f3daff1c09fbae7d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e332d3838393242462e737667)](https://php.net/)[![Software license](https://camo.githubusercontent.com/b3775a2de17853a90995faa104f941eef3ad3c40cc89e34b8b1eaea014614d4e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d425344253230332d2d436c617573652d626c75652e737667)](LICENSE)

The library relies on the `php.ini` settings. Every session ini directive can be reset with the `Koded\Session\SessionConfiguration` object.

Refer to php.ini session directives:

Usage
-----

[](#usage)

The session is started automatically by using one of the 2 methods:

### app configuration

[](#app-configuration)

```
[
    'session' => [
        // your ini "session." overwrites, without "session." prefix
    ]
]
```

### or using a `SessionMiddleware`

[](#or-using-a-sessionmiddleware)

include this middleware class in your middleware stack

```
// your middleware stack
$middleware = [
    SessionMiddleware::class
];
```

Session class and function
--------------------------

[](#session-class-and-function)

```
session()->get('key');
session()->set('key', 'value');
// etc.
```

The session class can be instantiated and used, but the function `session()`is recommended instead an instance of `Session` class.

Handlers Configuration
======================

[](#handlers-configuration)

The bare minimum is to define the handler you want to use for the session:

```
// in your configuration file

return [
    'session' => [
        'save_handler' => 'redis | memcache'
    ]
]
```

If you do not choose one of the Redis or Memcached, it defaults to `files`handler which is the PHP's default session mechanism.

However, the `files` handler might not be desirable if your application runs in Docker, Kubernetes, distributed environment, etc.

> The best choice for PHP sessions is Redis in almost all situations.

WARNING: Memcached may drop the session data, because it's nature. Use it with caution!

Redis handler
-------------

[](#redis-handler)

```
[
    'session' => [
        'save_handler' => 'redis'

        // OPTIONAL, these are the defaults
        'host' => 'localhost',
        'port' => 6379,
        'timeout' => 0.0,
        'retry' => 0,
        'db' => 0,

        'prefix' => 'sess:',
        'serializer' => 'php', // or "json"
        'binary' => false,     // TRUE for igbinary
    ]
]
```

A typical Redis settings:

- 1 server
- application + redis on the same machine
- Redis (127.0.0.1:6379)
- no auth (Redis is not available from outside)

```
[
    'session' => [
        'save_handler' => 'redis',
        'name'         => 'session-name',
        'prefix'       => 'sess:',

        // isolate the session data in other db
        'db'           => 1
    ]
]
```

To support huge volumes you need a good sysadmin skills and wast knowledge to set the Redis server(s).

Memcached handler
-----------------

[](#memcached-handler)

```
[
    'session' => [
        'save_handler' => 'memcached',

        // OPTIONAL: defaults to ['127.0.0.1', 11211]
        // If you have multiple memcached servers
        'servers' => [
            ['127.0.0.1', 11211],
            ['127.0.0.1', 11212],
            ['127.0.0.2']
            ...
        ],

        // OPTIONAL: the options are not mandatory
        'options' => [
            ...
        ]
    ]
]
```

A typical Memcached settings:

- 1 server
- application + memcached on the same machine
- Memcached (127.0.0.1:11211)

```
[
    'session' => [
        'save_handler' => 'memcached',
        'name'         => 'session-name',
        'prefix'       => 'sess.'
    ]
]
```

To support huge amount of users you need a decent amounts of RAM on your servers. But Memcached is a master technology for this, so you should be fine.

Files handler
-------------

[](#files-handler)

This one is not recommended for any serious business. It's fine only for small projects.

All session directives are copied from `php.ini`.

```
[
    'session' => [
        // OPTIONAL: defaults to "session_save_path()"
        // the path where to store the session data
        'save_path' => '/var/www/sessions',
        'serialize_handler' => 'php'
    ]
]
```

A typical native PHP session settings:

```
[
    'session' => [
        // really nothing,
        // skip this section in your configuration
    ]
]
```

You cannot use this handler if you've scaled your application, because the session data will most likely be handled randomly on a different instance for every HTTP request.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

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

Total

3

Last Release

326d ago

Major Versions

1.1.0 → 2.x-dev2025-06-23

PHP version history (2 changes)1.0.0PHP ~7.3

2.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/02c41fefd80a09d9f349706dbee9f45b9cfe539509881a05af4fa8d3517a878d?d=identicon)[kodeart](/maintainers/kodeart)

---

Top Contributors

[![kodeart](https://avatars.githubusercontent.com/u/202293?v=4)](https://github.com/kodeart "kodeart (84 commits)")

---

Tags

memcachedmiddlewarephp-sessionsredissessionsession-handlerredismemcachedsessionsession handler

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[jamm/memory

Key-value storage in memory. As a storage can be used: APC, Redis, Memcache, Shared memory. All storage objects have one interface, so you can switch them without changing the working code. Contains PHP Redis client.

13326.3k1](/packages/jamm-memory)[aplus/cache

Aplus Framework Cache Library

161.6M4](/packages/aplus-cache)[robinn/phpcacheadmin

A web dashboard for your favorite caching system.

4441.1k1](/packages/robinn-phpcacheadmin)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)

PHPackages © 2026

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