\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()
$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 : \MongoDB\Collection

Type

\MongoDB\Collection

$options

$options : array

Type

array

Methods

open()

open(  $savePath,   $sessionName) : boolean

Parameters

$savePath
$sessionName

Returns

boolean

validateId()

validateId(  $sessionId) : boolean

Parameters

$sessionId

Returns

boolean

read()

read(  $sessionId) : string

Parameters

$sessionId

Returns

string

write()

write(  $sessionId,   $data) : boolean

Parameters

$sessionId
$data

Returns

boolean

destroy()

destroy(  $sessionId) : boolean

Parameters

$sessionId

Returns

boolean

__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: https://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
array $options

Throws

\InvalidArgumentException

When "database" or "collection" not provided

close()

close() : boolean

Returns

boolean

gc()

gc(  $maxlifetime) : boolean

Parameters

$maxlifetime

Returns

boolean

updateTimestamp()

updateTimestamp(  $sessionId,   $data) : boolean

Parameters

$sessionId
$data

Returns

boolean

doRead()

doRead(\Symfony\Component\HttpFoundation\Session\Storage\Handler\string  $sessionId) : string

Parameters

\Symfony\Component\HttpFoundation\Session\Storage\Handler\string $sessionId

Returns

string

doWrite()

doWrite(\Symfony\Component\HttpFoundation\Session\Storage\Handler\string  $sessionId, \Symfony\Component\HttpFoundation\Session\Storage\Handler\string  $data) : boolean

Parameters

\Symfony\Component\HttpFoundation\Session\Storage\Handler\string $sessionId
\Symfony\Component\HttpFoundation\Session\Storage\Handler\string $data

Returns

boolean

doDestroy()

doDestroy(\Symfony\Component\HttpFoundation\Session\Storage\Handler\string  $sessionId) : boolean

Parameters

\Symfony\Component\HttpFoundation\Session\Storage\Handler\string $sessionId

Returns

boolean

getMongo()

getMongo() : \MongoDB\Client

Returns

\MongoDB\Client

getCollection()

getCollection()