MongoDB-based sessions implementation.
use web\session\InMongoDB;
use com\mongodb\MongoConnection;
$conn= new MongoConnection('mongodb://localhost');
$sessions= new InMongoDB($conn->collection('test', 'sessions'));
By default, cleaning up expired sessions is handled by the implementation. For a more performant version, use TTL indexes as follows.
Issue the following in MongoDB shell:
db.sessions.createIndex({"_created": 1}, {expireAfterSeconds: 86400})
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.