class MongoDbSessionHandler extends AbstractSessionHandler

Session handler using the mongodb/mongodb package and MongoDB driver extension.

Methods

open($savePath, $sessionName)

{@inheritdoc}

string
doRead(string $sessionId)

No description

bool
doWrite(string $sessionId, string $data)

No description

bool
doDestroy(string $sessionId)

No description

validateId($sessionId)

{@inheritdoc}

read($sessionId)

{@inheritdoc}

write($sessionId, $data)

{@inheritdoc}

destroy($sessionId)

{@inheritdoc}

__construct(Client $mongo, array $options)

Constructor.

close()

{@inheritdoc}

gc($maxlifetime)

{@inheritdoc}

updateTimestamp($sessionId, $data)

{@inheritdoc}

Client
getMongo()

No description

Details

open($savePath, $sessionName)

{@inheritdoc}

Parameters

$savePath
$sessionName

at line 160
protected string doRead(string $sessionId)

Parameters

string $sessionId

Return Value

string

at line 120
protected bool doWrite(string $sessionId, string $data)

Parameters

string $sessionId
string $data

Return Value

bool

at line 96
protected bool doDestroy(string $sessionId)

Parameters

string $sessionId

Return Value

bool

validateId($sessionId)

{@inheritdoc}

Parameters

$sessionId

read($sessionId)

{@inheritdoc}

Parameters

$sessionId

in AbstractSessionHandler at line 103
write($sessionId, $data)

{@inheritdoc}

Parameters

$sessionId
$data

in AbstractSessionHandler at line 120
destroy($sessionId)

{@inheritdoc}

Parameters

$sessionId

at line 69
__construct(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

Client $mongo A MongoDB\Client instance
array $options An associative array of field options

Exceptions

InvalidArgumentException When "database" or "collection" not provided

at line 88
close()

{@inheritdoc}

at line 108
gc($maxlifetime)

{@inheritdoc}

Parameters

$maxlifetime

at line 142
updateTimestamp($sessionId, $data)

{@inheritdoc}

Parameters

$sessionId
$data

at line 189
protected Client getMongo()

Return Value

Client