PHPackages                             xp-forge/mongo-sessions - 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. xp-forge/mongo-sessions

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

xp-forge/mongo-sessions
=======================

MongoDB Sessions

v4.0.0(4mo ago)11.3k↓64.9%BSD-3-ClausePHPPHP &gt;=7.4.0CI passing

Since Apr 12Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/xp-forge/mongo-sessions)[ Packagist](https://packagist.org/packages/xp-forge/mongo-sessions)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-forge-mongo-sessions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

MongoDB Sessions
================

[](#mongodb-sessions)

[![Build status on GitHub](https://github.com/xp-forge/mongo-sessions/workflows/Tests/badge.svg)](https://github.com/xp-forge/mongo-sessions/actions)[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/3314cc731bd812a478e83a8831e768a99343500719b3609b2d63f3515c8cb21b/68747470733a2f2f706f7365722e707567782e6f72672f78702d666f7267652f6d6f6e676f2d73657373696f6e732f76657273696f6e2e737667)](https://packagist.org/packages/xp-forge/mongo-sessions)

[MongoDB](https://www.mongodb.com/)-based [sessions implementation](https://github.com/xp-forge/sessions).

Example
-------

[](#example)

```
use web\session\InMongoDB;
use com\mongodb\MongoConnection;

$conn= new MongoConnection('mongodb://localhost');
$sessions= new InMongoDB($conn->collection('test', 'sessions'));
```

Session expiry
--------------

[](#session-expiry)

By default, cleaning up expired sessions is handled by the implementation. For a more performant version, use [TTL indexes](https://www.mongodb.com/docs/manual/core/index-ttl/) as follows.

### Setup collection

[](#setup-collection)

Issue the following in MongoDB shell:

```
db.sessions.createIndex({"_created": 1}, {expireAfterSeconds: 86400})
```

### Add TTL flag

[](#add-ttl-flag)

Pass `InMongoDB::USING_TTL` as second parameter to the *InMongoDB* constructor:

```
$sessions= new InMongoDB($conn->collection('test', 'sessions'), InMongoDB::USING_TTL);
```

This will use the *expireAfterSeconds* value as session duration.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance75

Regular maintenance activity

Popularity20

Limited adoption so far

Community7

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

Recently: every ~163 days

Total

15

Last Release

134d ago

Major Versions

v0.4.1 → v1.0.02022-06-11

v1.3.0 → v2.0.02024-02-04

v2.2.1 → v3.0.02025-01-25

v3.0.0 → v4.0.02026-01-04

PHP version history (2 changes)v0.1.0PHP &gt;=7.0.0

v3.0.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d18d882c8b4aaf3466432f64018214f2771eda333202175431ee7233795376?d=identicon)[thekid](/maintainers/thekid)

---

Top Contributors

[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (54 commits)")

---

Tags

mongodbphp7php8session-storagesessionsxp-frameworkmodulexp

### Embed Badge

![Health badge](/badges/xp-forge-mongo-sessions/health.svg)

```
[![Health](https://phpackages.com/badges/xp-forge-mongo-sessions/health.svg)](https://phpackages.com/packages/xp-forge-mongo-sessions)
```

###  Alternatives

[doctrine/doctrine-orm-module

Laminas Module that provides Doctrine ORM functionality

4407.3M293](/packages/doctrine-doctrine-orm-module)[doctrine/doctrine-module

Laminas Module that provides Doctrine basic functionality required for ORM and ODM modules

3957.9M116](/packages/doctrine-doctrine-module)[doctrine/doctrine-mongo-odm-module

Laminas Module which provides Doctrine MongoDB ODM functionality

86676.6k35](/packages/doctrine-doctrine-mongo-odm-module)

PHPackages © 2026

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