PHPackages                             ghostff/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. [Database &amp; ORM](/categories/database)
4. /
5. ghostff/session

ActiveLibrary[Database &amp; ORM](/categories/database)

ghostff/session
===============

PHP Session Manager (non-blocking, flash, segment, session encryption).

v3.1.0(8mo ago)382.0k↓48.4%8[1 PRs](https://github.com/Ghostff/Session/pulls)20BSDPHPPHP &gt;=7.4CI passing

Since Jun 24Pushed 3mo agoCompare

[ Source](https://github.com/Ghostff/Session)[ Packagist](https://packagist.org/packages/ghostff/session)[ RSS](/packages/ghostff-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (9)Used By (2)

Session PHP(7.4+)
=================

[](#session-php74)

PHP Session Manager (non-blocking, flash, segment, session encryption). Uses PHP [open\_ssl](http://php.net/manual/en/book.openssl.php) for **optional** encrypt/decryption of session data.

### Driver Support Scope

[](#driver-support-scope)

[![file](https://camo.githubusercontent.com/518c38fed937ef125be5273cc93501bc518a171b5a6057473fc90bed498181ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46494c452d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/518c38fed937ef125be5273cc93501bc518a171b5a6057473fc90bed498181ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46494c452d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) [![cookie](https://camo.githubusercontent.com/3e650892fcb8167c4acdb97763f843543dfeb57898b04f2a21285527d45dd9f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f434f4f4b49452d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/3e650892fcb8167c4acdb97763f843543dfeb57898b04f2a21285527d45dd9f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f434f4f4b49452d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) [![mysql](https://camo.githubusercontent.com/700a0fe8414f6402f60a4264befe3633adc26fd544eff3a7ef7d87a7e44a2d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d5953514c2d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/700a0fe8414f6402f60a4264befe3633adc26fd544eff3a7ef7d87a7e44a2d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d5953514c2d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) [![sqlite](https://camo.githubusercontent.com/cf3b94df7a02461d6b6de72aca6440c4b38edde215055b79005184bfe2a1828f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53514c4954452d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/cf3b94df7a02461d6b6de72aca6440c4b38edde215055b79005184bfe2a1828f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53514c4954452d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) [![memcached](https://camo.githubusercontent.com/4e2059b755339e7875ade7e55600d62f202aa292722b5111d4bd27d8c03c2b68/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d454d4341434845442d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/4e2059b755339e7875ade7e55600d62f202aa292722b5111d4bd27d8c03c2b68/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d454d4341434845442d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) [![redis](https://camo.githubusercontent.com/d8c76aedf7abdc9fa8135a6193747f3d10acf5a80998d40ca82ac5e5ae0b0145/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52454449532d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d8c76aedf7abdc9fa8135a6193747f3d10acf5a80998d40ca82ac5e5ae0b0145/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52454449532d636f6d706c657465642d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) ![license](https://camo.githubusercontent.com/c875a64244fbf03b534ba5ec3183ad400592cd523b294ef61c47b903f5a18845/68747470733a2f2f696d672e736869656c64732e696f2f707970692f6c2f446a616e676f2e7376673f7374796c653d666c61742d737175617265) [![Minimum PHP Version](https://camo.githubusercontent.com/5b837c0ea28a82c831bf4c47f453e3d187776b9407dab996a705b32223ca2cae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344253230372e342d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net/releases/7_4_0.php)

Installation
============

[](#installation)

You can download the Latest [release version ](https://github.com/Ghostff/Session/releases/) as a standalone, alternatively you can use [Composer](https://getcomposer.org/)

```
composer require ghostff/session
```

Basic usage
-----------

[](#basic-usage)

```
# Start session with default configurations.
$session = new Session();

$session->set('email', 'foo@bar.com');

echo $session->get('email');
```

Configuration Options
---------------------

[](#configuration-options)

```
# use custom configuration file.
Session::setConfigurationFile('path/to/my/config.php');

# overriding specific configuration settings
Session::updateConfiguration([
    Session::CONFIG_DRIVER        => Redis::class,
    Session::CONFIG_START_OPTIONS => [
        Session::CONFIG_START_OPTIONS_SAVE_PATH => __DIR__ . '/tmp'
    ]
]);

# override a configuration for current session instance
$session = new Session([Session::CONFIG_ENCRYPT_DATA => true]);
```

Initializing Session
--------------------

[](#initializing-session)

```
# Start session with an auto generated id.
$session = new Session();

# Start session with custom ID
$session = new Session(null, bin2hex(random_bytes(32)));
```

Using Segment *:Session*
------------------------

[](#using-segment-session)

```
 $segment = $session->segment('my_segment');
```

Retrieving Session ID *:string*
-------------------------------

[](#retrieving-session-id--string)

```
echo $session->id();
```

Committing changes *:void*
--------------------------

[](#committing-changes-void)

```
# Opens, writes and closes session.
$session->commit();
```

Setting Session Data *:Session*
-------------------------------

[](#setting-session-data-session)

```
$session->set('fname', 'foo');
# Setting Segment
$segment->set('name', 'bar');

# Setting Flash
$session->setFlash('name', 'foobar');
# Setting Segment Flash
$segment->setFlash('name', 'barfoo');

$session->commit();
```

Retrieving Session Data *:mixed*
--------------------------------

[](#retrieving-session-data-mixed)

```
echo $session->get('name'); # outputs foo
echo $session->getOrDefault('unset_value', 'not found'); # outputs not found
# Retrieving Segment
echo $segment->get('name'); # outputs bar
echo $segment->getOrDefault('unset_value', 'not found'); # outputs not found

# Retrieving Flash
echo $session->getFlash('name'); # outputs foobar
echo $session->getFlashOrDefault('name', 'not found'); # outputs not found
# Retrieving Segment Flash
echo $segment->getFlash('name'); # outputs barfoo
echo $segment->getFlashOrDefault('name', 'not found'); # outputs not found
```

Removing Session Data *:Session*
--------------------------------

[](#removing-session-data-session)

```
$session->del('name');
# Removing Segment
$segment->del('name');

# Removing Flash
$session->delFlash('name');
# Removing Segment Flash
$segment->delFlash('name');
```

Retrieve all session or segment data *:array*
---------------------------------------------

[](#retrieve-all-session-or-segment-data-array)

```
$session->getAll();
# Retrieve only in specified segment.
$session->getAll('my_segment_name');
```

Check if variable exist in current session namespace *:bool*
------------------------------------------------------------

[](#check-if-variable-exist-in-current-session-namespace-bool)

```
$session->exist('name');
# Search flashes
$session->exist('name', true);
```

Removing all data in current segment *:Session*
-----------------------------------------------

[](#removing-all-data-in-current-segment-session)

```
$session->clear();
```

Destroying session *:void*
--------------------------

[](#destroying-session-void)

```
$session->destroy();
```

Regenerate session ID *:void*
-----------------------------

[](#regenerate-session-id-void)

```
$session->rotate();
# Delete the old associated session file or not
$session->rotate(true);
```

Setting Queued Session Data *:Session*
--------------------------------------

[](#setting-queued-session-data-session)

```
$session->push('age', 10)
        ->push('age', 20)
        ->push('age', 30)
        ->push('age', 40);
```

Retrieving (pop/shift) Queued Session Data *:mixed*
---------------------------------------------------

[](#retrieving-popshift-queued-session-data-mixed)

```
echo $session->pop('age', true);  # outputs 10
echo $session->pop('age', true);  # outputs 20
echo $session->pop('age');        # outputs 40
echo $session->pop('age');        # outputs 30
```

Driver configuration
--------------------

[](#driver-configuration)

You can provide your own database connection (PDO, Memcached, Redis, etc). Provide the connection before constructing the session:

```
// Example: supplying a PDO connection
$pdo = new PDO('mysql:host=127.0.0.1;dbname=sessions', 'user', 'pass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

Session::setConnection(Session::CONFIG_MYSQL_DS, $pdo);

// Then construct your session (the configured driver will use this connection)
$session = new Session();
```

Similarly, you can set connections for:

- `Session::CONFIG_SQLITE_DS` with a PDO SQLite connection
- `Session::CONFIG_MEMCACHED_DS` with a Memcached instance
- `Session::CONFIG_REDIS_DS` with a Redis instance

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance72

Regular maintenance activity

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~501 days

Recently: every ~724 days

Total

7

Last Release

241d ago

Major Versions

v1.03.0 → v2.0.02022-01-14

v2.1.0 → v3.0.02024-07-24

PHP version history (2 changes)v1.0.0PHP &gt;=7.0.0

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15882122?v=4)[ghostff](/maintainers/Ghostff)[@Ghostff](https://github.com/Ghostff)

---

Top Contributors

[![Ghostff](https://avatars.githubusercontent.com/u/15882122?v=4)](https://github.com/Ghostff "Ghostff (96 commits)")[![keskinonur](https://avatars.githubusercontent.com/u/9061586?v=4)](https://github.com/keskinonur "keskinonur (3 commits)")[![n0nag0n](https://avatars.githubusercontent.com/u/2322095?v=4)](https://github.com/n0nag0n "n0nag0n (1 commits)")

---

Tags

encryptionflashmemcachedmysqlnon-blockingphp7redissessionsession-encryptionsession-managementsession-phpsqlitenon-blockingsqlredismemcachedsessionsegmentsecured-sessionsession-manger

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[matthiasmullie/scrapbook

Scrapbook is a PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APCu, SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

3212.5M32](/packages/matthiasmullie-scrapbook)[malkusch/lock

Mutex library for exclusive code execution.

9459.6M27](/packages/malkusch-lock)[aplus/session

Aplus Framework Session Library

2141.6M3](/packages/aplus-session)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[arvenil/ninja-mutex

Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking

1873.7M27](/packages/arvenil-ninja-mutex)

PHPackages © 2026

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