MongoDbSessionHandler
extends AbstractSessionHandler
in package
Session handler using the mongodb/mongodb package and MongoDB driver extension.
Tags
Table of Contents
Properties
- $collection : mixed
- $igbinaryEmptyData : string
- $mongo : mixed
- $newSessionId : string|null
- $options : array<string|int, mixed>
- $prefetchData : string
- $prefetchId : string
- $sessionName : string
Methods
- __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
mixed
$collection
$igbinaryEmptyData
private
string
$igbinaryEmptyData
$mongo
private
mixed
$mongo
$newSessionId
private
string|null
$newSessionId
= null
$options
private
array<string|int, mixed>
$options
$prefetchData
private
string
$prefetchData
$prefetchId
private
string
$prefetchId
$sessionName
private
string
$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
close()
public
close() : bool
Return values
booldestroy()
public
destroy(string $sessionId) : bool
Parameters
- $sessionId : string
Return values
boolgc()
public
gc(int $maxlifetime) : int|false
Parameters
- $maxlifetime : int
Return values
int|falseopen()
public
open(string $savePath, string $sessionName) : bool
Parameters
- $savePath : string
- $sessionName : string
Return values
boolread()
public
read(string $sessionId) : string
Parameters
- $sessionId : string
Return values
stringupdateTimestamp()
public
updateTimestamp(string $sessionId, string $data) : bool
Parameters
- $sessionId : string
- $data : string
Return values
boolvalidateId()
public
validateId(string $sessionId) : bool
Parameters
- $sessionId : string
Return values
boolwrite()
public
write(string $sessionId, string $data) : bool
Parameters
- $sessionId : string
- $data : string
Return values
booldoDestroy()
protected
doDestroy(string $sessionId) : bool
Parameters
- $sessionId : string
Return values
booldoRead()
protected
doRead(string $sessionId) : string
Parameters
- $sessionId : string
Return values
stringdoWrite()
protected
doWrite(string $sessionId, string $data) : bool
Parameters
- $sessionId : string
- $data : string
Return values
boolgetMongo()
protected
getMongo() : Client
Return values
ClientgetCollection()
private
getCollection() : Collection