class MongoDbSessionHandler implements SessionHandlerInterface

Methods

__construct(Mongo|MongoClient|Client $mongo, array $options)

Constructor.

open($savePath, $sessionName)

{@inheritdoc}

close()

{@inheritdoc}

destroy($sessionId)

{@inheritdoc}

gc($maxlifetime)

{@inheritdoc}

write($sessionId, $data)

{@inheritdoc}

read($sessionId)

{@inheritdoc}

Mongo|MongoClient|Client
getMongo()

Return a Mongo instance.

Details

at line 65
__construct(Mongo|MongoClient|Client $mongo, array $options)

Constructor.

List of available options: * database: The name of the database [required] * collection: The name of the collection [required] * id_field: The field name for storing the session id [default: _id] * data_field: The field name for storing the session data [default: data] * time_field: The field name for storing the timestamp [default: time] * expiry_field: The field name for storing the expiry-timestamp [default: expires_at]

It is strongly recommended to put an index on the expiry_field for garbage-collection. Alternatively it's possible to automatically expire the sessions in the database as described below:

A TTL collections can be used on MongoDB 2.2+ to cleanup expired sessions automatically. Such an index can for example look like this:

db.<session-collection>.ensureIndex(
    { "<expiry-field>": 1 },
    { "expireAfterSeconds": 0 }
)

More details on: http://docs.mongodb.org/manual/tutorial/expire-data/

If you use such an index, you can drop gc_probability to 0 since no garbage-collection is required.

Parameters

Mongo|MongoClient|Client $mongo A MongoDB\Client, MongoClient or Mongo instance
array $options An associative array of field options

Exceptions

InvalidArgumentException When MongoClient or Mongo instance not provided
InvalidArgumentException When "database" or "collection" not provided

at line 88
open($savePath, $sessionName)

{@inheritdoc}

Parameters

$savePath
$sessionName

at line 96
close()

{@inheritdoc}

at line 104
destroy($sessionId)

{@inheritdoc}

Parameters

$sessionId

at line 118
gc($maxlifetime)

{@inheritdoc}

Parameters

$maxlifetime

at line 132
write($sessionId, $data)

{@inheritdoc}

Parameters

$sessionId
$data

at line 164
read($sessionId)

{@inheritdoc}

Parameters

$sessionId

at line 201
protected Mongo|MongoClient|Client getMongo()

Return a Mongo instance.

Return Value

Mongo|MongoClient|Client