\Symfony\Component\HttpFoundation\Session\Storage\HandlerMongoDbSessionHandler

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

Summary

Methods
Properties
Constants
open()
validateId()
read()
write()
destroy()
__construct()
close()
gc()
updateTimestamp()
No public properties found
No constants found
doRead()
doWrite()
doDestroy()
getMongo()
No protected properties found
N/A
getCollection()
createDateTime()
$sessionName
$prefetchId
$prefetchData
$newSessionId
$igbinaryEmptyData
$mongo
$collection
$options
N/A

Properties

$sessionName

$sessionName : 

Type

$prefetchId

$prefetchId : 

Type

$prefetchData

$prefetchData : 

Type

$newSessionId

$newSessionId : 

Type

$igbinaryEmptyData

$igbinaryEmptyData : 

Type

$mongo

$mongo : 

Type

$collection

$collection : \MongoCollection

Type

\MongoCollection

$options

$options : array

Type

array

Methods

open()

open(  $savePath,   $sessionName) 

{@inheritdoc}

Parameters

$savePath
$sessionName

validateId()

validateId(  $sessionId) : boolean

Checks if a session identifier already exists or not.

Parameters

$sessionId

Returns

boolean

read()

read(  $sessionId) 

{@inheritdoc}

Parameters

$sessionId

write()

write(  $sessionId,   $data) 

{@inheritdoc}

Parameters

$sessionId
$data

destroy()

destroy(  $sessionId) 

{@inheritdoc}

Parameters

$sessionId

__construct()

__construct(\MongoDB\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

\MongoDB\Client $mongo

A MongoDB\Client instance

array $options

An associative array of field options

Throws

\InvalidArgumentException

When MongoClient or Mongo instance not provided

\InvalidArgumentException

When "database" or "collection" not provided

close()

close() 

{@inheritdoc}

gc()

gc(  $maxlifetime) 

{@inheritdoc}

Parameters

$maxlifetime

updateTimestamp()

updateTimestamp(  $sessionId,   $data) 

{@inheritdoc}

Parameters

$sessionId
$data

doRead()

doRead(string  $sessionId) : string

Parameters

string $sessionId

Returns

string

doWrite()

doWrite(string  $sessionId, string  $data) : boolean

Parameters

string $sessionId
string $data

Returns

boolean

doDestroy()

doDestroy(string  $sessionId) : boolean

Parameters

string $sessionId

Returns

boolean

getMongo()

getMongo() : \Mongo|\MongoClient|\MongoDB\Client

Return a Mongo instance.

Returns

\Mongo|\MongoClient|\MongoDB\Client

getCollection()

getCollection() : \MongoCollection

Return a "MongoCollection" instance.

Returns

\MongoCollection

createDateTime()

createDateTime(integer  $seconds = null) : \MongoDate|\MongoDB\BSON\UTCDateTime

Create a date object using the class appropriate for the current mongo connection.

Return an instance of a MongoDate or \MongoDB\BSON\UTCDateTime

Parameters

integer $seconds

An integer representing UTC seconds since Jan 1 1970. Defaults to now.

Returns

\MongoDate|\MongoDB\BSON\UTCDateTime