Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • MemcachedSessionHandler
  • MemcacheSessionHandler
  • MongoDbSessionHandler
  • NativeFileSessionHandler
  • NativeSessionHandler
  • NullSessionHandler
  • PdoSessionHandler
  • WriteCheckSessionHandler
  • Overview
  • Namespace
  • Class
  • Tree

Class MongoDbSessionHandler

MongoDB session handler.

Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler implements SessionHandlerInterface
Namespace: Symfony\Component\HttpFoundation\Session\Storage\Handler
Author: Markus Bachmann <markus.bachmann@bachi.biz>
Located at Storage/Handler/MongoDbSessionHandler.php
Methods summary
public
# __construct( Mongo|MongoClient|MongoDB\Client $mongo, array $options )

Constructor.

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.

Parameters

$mongo
Mongo|MongoClient|MongoDB\Client
$mongo A MongoDB\Client, MongoClient or Mongo instance
$options
array
$options An associative array of field options

Throws

InvalidArgumentException
When MongoClient or Mongo instance not provided
InvalidArgumentException
When "database" or "collection" not provided
public
# open( mixed $savePath, mixed $sessionName )

Implementation of

SessionHandlerInterface::open()
public
# close( )

Implementation of

SessionHandlerInterface::close()
public
# destroy( mixed $sessionId )

Implementation of

SessionHandlerInterface::destroy()
public
# gc( mixed $maxlifetime )

Implementation of

SessionHandlerInterface::gc()
public
# write( mixed $sessionId, mixed $data )

Implementation of

SessionHandlerInterface::write()
public
# read( mixed $sessionId )

Implementation of

SessionHandlerInterface::read()
protected Mongo|MongoClient|MongoDB\Client
# getMongo( )

Return a Mongo instance.

Return a Mongo instance.

Returns

Mongo|MongoClient|MongoDB\Client
Ratchet API documentation generated by ApiGen 2.8.0