Installation guide

Before you can actually use the session handler, you need to create a table in which to store the sessions. This can
be done ahead of time through the AWS Console for Amazon DynamoDB, or you can use the session handler
object (which you've already configured with the table name) by doing the following:
$sessionHandler->createSessionsTable(5, 5);
The two parameters for this function are used to specify the read and write provisioned throughput for the table,
respectively.
Note
The createSessionsTable function uses the TableExists waiter internally, so this function call will block
until the table exists and is ready to be used.
3. Use PHP sessions like normal
Once the session handler is registered and the table exists, you can write to and read from the session using the
$_SESSION superglobal, just like you normally do with PHP's default session handler. The DynamoDB Session
Handler encapsulates and abstracts the interactions with Amazon DynamoDB and enables you to simply use PHP's
native session functions and interface.
// Start the session
session_start();
// Alter the session data
$_SESSION['user.name'] = 'jeremy';
$_SESSION['user.role'] = 'admin';
// Close the session (optional, but recommended)
session_write_close();
Configuration
You may configure the behavior of the session handler using the following options. All options are optional, but you
should make sure to understand what the defaults are.
table_name The name of the DynamoDB table in which to store the sessions. This defaults to
sessions.
hash_key The name of the hash key in the DynamoDB sessions table. This defaults to id.
session_lifetime The lifetime of an inactive session before it should be garbage collected. If it is not
provided, then the actual lifetime value that will be used is
ini_get('session.gc_maxlifetime').
consistent_read Whether or not the session handler should use consistent reads for the GetItem
operation. This defaults to true.
locking_strategy The strategy used for doing session locking. By default the handler uses the
NullLockingStrategy, which means that session locking is not enabled (see the
Session Locking section for more information). Valid values for this option include null,
'null', 'pessemistic', or an instance of NullLockingStrategy or
PessimisticLockingStrategy.
automatic_gc Whether or not to use PHP's session auto garbage collection. This defaults to the
value of (bool) ini_get('session.gc_probability'), but the recommended
value is false. (see the Garbage Collection section for more information).
DynamoDB Session Handler
128