Class SessionHandler
- Aws\DynamoDb\SessionHandler implements SessionHandlerInterface
- Namespace: Aws\DynamoDb
- Located at DynamoDb/SessionHandler.php
Provides an interface for using Amazon DynamoDB as a session store by hooking
into PHP's session handler hooks. Once registered, You may use the native
$_SESSION
superglobal and session functions, and the sessions will be
stored automatically in DynamoDB. DynamoDB is a great session storage
solution due to its speed, scalability, and fault tolerance.
For maximum performance, we recommend that you keep the size of your sessions small. Locking is disabled by default, since it can drive up latencies and costs under high traffic. Only turn it on if you need it.
By far, the most expensive operation is garbage collection. Therefore, we encourage you to carefully consider your session garbage collection strategy. Note: the DynamoDB Session Handler does not allow garbage collection to be triggered randomly. You must run garbage collection manually or through other automated means using a cron job or similar scheduling technique.
Methods Summary
-
static
fromClient ( Aws\DynamoDb\DynamoDbClient $client, array $config = [] )
Creates a new DynamoDB Session Handler.
- __construct ( Aws\DynamoDb\SessionConnectionInterface $connection )
-
register ( )
Register the DynamoDB session handler.
- open ( $savePath, $sessionName )
- close ( )
- read ( $id )
- write ( $id, $data )
- destroy ( $id )
- gc ( $maxLifetime )
-
garbageCollect ( )
Triggers garbage collection on expired sessions.
Methods Details
static
Aws\DynamoDb\SessionHandler
fromClient (
Aws\DynamoDb\DynamoDbClient
$client,
array
$config = []
)
Creates a new DynamoDB Session Handler.
The configuration array accepts the following array keys and values: - table_name: Name of table to store the sessions. - hash_key: Name of hash key in table. Default: "id". - data_attribute: Name of the data attribute in table. Default: "data". - session_lifetime: Lifetime of inactive sessions expiration. - session_lifetime_attribute: Name of the session life time attribute in table. Default: "expires". - consistent_read: Whether or not to use consistent reads. - batch_config: Batch options used for garbage collection. - locking: Whether or not to use session locking. - max_lock_wait_time: Max time (s) to wait for lock acquisition. - min_lock_retry_microtime: Min time (µs) to wait between lock attempts. - max_lock_retry_microtime: Max time (µs) to wait between lock attempts.
You can find the full list of parameters and defaults within the trait Aws\DynamoDb\SessionConnectionConfigTrait
Parameters
Aws\DynamoDb\DynamoDbClient |
$client | Client for doing DynamoDB operations |
array | $config = [] | Configuration for the Session Handler |
Returns
Aws\DynamoDb\SessionHandler |
__construct (
Aws\DynamoDb\SessionConnectionInterface
$connection
)
Parameters
Aws\DynamoDb\SessionConnectionInterface |
$connection |
boolean register ( )
Register the DynamoDB session handler.
Returns
boolean Whether or not the handler was registered. |
Codecoverageignore
open ( $savePath, $sessionName )
Implementation of
SessionHandlerInterface::open()
close ( )
Implementation of
SessionHandlerInterface::close()
read ( $id )
Implementation of
SessionHandlerInterface::read()
write ( $id, $data )
Implementation of
SessionHandlerInterface::write()
destroy ( $id )
Implementation of
SessionHandlerInterface::destroy()
gc ( $maxLifetime )
Implementation of
SessionHandlerInterface::gc()
garbageCollect ( )
Triggers garbage collection on expired sessions.