Documentation

MongoDbSessionHandler extends AbstractSessionHandler
in package

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

Tags
author

Markus Bachmann markus.bachmann@bachi.biz

see
https://packagist.org/packages/mongodb/mongodb
see
https://php.net/mongodb

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

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
throws
InvalidArgumentException

When "database" or "collection" not provided

Return values
mixed

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

Search results