MongoDbSessionHandler
extends AbstractSessionHandler
in package
Session handler using the mongodb/mongodb package and MongoDB driver extension.
Tags
Table of Contents
- $collection : Collection
- $igbinaryEmptyData : mixed
- $mongo : mixed
- $newSessionId : mixed
- $options : array<string|int, mixed>
- $prefetchData : mixed
- $prefetchId : mixed
- $sessionName : mixed
- __construct() : mixed
- Constructor.
- close() : bool
- destroy() : bool
- gc() : int|false
- open() : bool
- read() : string
- updateTimestamp() : bool
- validateId() : bool
- write() : bool
- doDestroy() : bool
- doRead() : string
- doWrite() : bool
- getMongo() : Client
- getCollection() : Collection
Properties
$collection
private
Collection
$collection
$igbinaryEmptyData
private
mixed
$igbinaryEmptyData
$mongo
private
mixed
$mongo
$newSessionId
private
mixed
$newSessionId
$options
private
array<string|int, mixed>
$options
$prefetchData
private
mixed
$prefetchData
$prefetchId
private
mixed
$prefetchId
$sessionName
private
mixed
$sessionName
Methods
__construct()
Constructor.
public
__construct(Client $mongo, array<string|int, mixed> $options) : mixed
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>.createIndex(
{ "<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
- $mongo : Client
- $options : array<string|int, mixed>
Tags
Return values
mixed —close()
public
close() : bool
Return values
bool —destroy()
public
destroy(mixed $sessionId) : bool
Parameters
- $sessionId : mixed
Return values
bool —gc()
public
gc(mixed $maxlifetime) : int|false
Parameters
- $maxlifetime : mixed
Return values
int|false —open()
public
open(mixed $savePath, mixed $sessionName) : bool
Parameters
- $savePath : mixed
- $sessionName : mixed
Return values
bool —read()
public
read(mixed $sessionId) : string
Parameters
- $sessionId : mixed
Return values
string —updateTimestamp()
public
updateTimestamp(mixed $sessionId, mixed $data) : bool
Parameters
- $sessionId : mixed
- $data : mixed
Return values
bool —validateId()
public
validateId(mixed $sessionId) : bool
Parameters
- $sessionId : mixed
Return values
bool —write()
public
write(mixed $sessionId, mixed $data) : bool
Parameters
- $sessionId : mixed
- $data : mixed
Return values
bool —doDestroy()
protected
doDestroy(string $sessionId) : bool
Parameters
- $sessionId : string
Return values
bool —doRead()
protected
doRead(string $sessionId) : string
Parameters
- $sessionId : string
Return values
string —doWrite()
protected
doWrite(string $sessionId, string $data) : bool
Parameters
- $sessionId : string
- $data : string
Return values
bool —getMongo()
protected
getMongo() : Client
Return values
Client —getCollection()
private
getCollection() : Collection