class MongoDbSessionHandler extends AbstractSessionHandler
Session handler using the mongodb/mongodb package and MongoDB driver extension.
open($savePath, $sessionName) {@inheritdoc} | from AbstractSessionHandler | |
string | doRead(string $sessionId) | |
bool | doWrite(string $sessionId, string $data) | |
bool | doDestroy(string $sessionId) | |
validateId($sessionId) {@inheritdoc} | from AbstractSessionHandler | |
read($sessionId) {@inheritdoc} | from AbstractSessionHandler | |
write($sessionId, $data) {@inheritdoc} | from AbstractSessionHandler | |
destroy($sessionId) {@inheritdoc} | from AbstractSessionHandler | |
__construct(Client $mongo, array $options) Constructor. | ||
close() {@inheritdoc} | ||
gc($maxlifetime) {@inheritdoc} | ||
updateTimestamp($sessionId, $data) {@inheritdoc} | ||
Client | getMongo() |
{@inheritdoc}
$savePath | ||
$sessionName |
string | $sessionId |
string |
string | $sessionId | |
string | $data |
bool |
string | $sessionId |
bool |
{@inheritdoc}
$sessionId |
{@inheritdoc}
$sessionId |
{@inheritdoc}
$sessionId | ||
$data |
{@inheritdoc}
$sessionId |
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.
Client | $mongo | A MongoDB\Client instance |
array | $options | An associative array of field options |
InvalidArgumentException | When "database" or "collection" not provided |
{@inheritdoc}
{@inheritdoc}
$maxlifetime |
{@inheritdoc}
$sessionId | ||
$data |
Client |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.html