https://github.com/xp-forge/mongo-sessions
MongoDB Sessions
https://github.com/xp-forge/mongo-sessions
mongodb php7 php8 session-storage sessions xp-framework
Last synced: 4 months ago
JSON representation
MongoDB Sessions
- Host: GitHub
- URL: https://github.com/xp-forge/mongo-sessions
- Owner: xp-forge
- Created: 2022-04-12T17:18:14.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-25T14:52:03.000Z (over 1 year ago)
- Last Synced: 2025-04-15T05:26:21.905Z (about 1 year ago)
- Topics: mongodb, php7, php8, session-storage, sessions, xp-framework
- Language: PHP
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
MongoDB Sessions
================
[](https://github.com/xp-forge/mongo-sessions/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagist.org/packages/xp-forge/mongo-sessions)
[MongoDB](https://www.mongodb.com/)-based [sessions implementation](https://github.com/xp-forge/sessions).
Example
-------
```php
use web\session\InMongoDB;
use com\mongodb\MongoConnection;
$conn= new MongoConnection('mongodb://localhost');
$sessions= new InMongoDB($conn->collection('test', 'sessions'));
```
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
Issue the following in MongoDB shell:
```javascript
db.sessions.createIndex({"_created": 1}, {expireAfterSeconds: 86400})
```
### Add TTL flag
Pass `InMongoDB::USING_TTL` as second parameter to the *InMongoDB* constructor:
```php
$sessions= new InMongoDB($conn->collection('test', 'sessions'), InMongoDB::USING_TTL);
```
This will use the *expireAfterSeconds* value as session duration.