SessionHandler
in package
implements
SessionHandlerInterface
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.
Table of Contents
Interfaces
- SessionHandlerInterface
Methods
- __construct() : mixed
- close() : bool
- Close a session from writing.
- destroy() : bool
- Delete a session stored in DynamoDB.
- fromClient() : SessionHandler
- Creates a new DynamoDB Session Handler.
- garbageCollect() : mixed
- Triggers garbage collection on expired sessions.
- gc() : bool
- Satisfies the session handler interface, but does nothing. To do garbage collection, you must manually call the garbageCollect() method.
- open() : bool
- Open a session for writing. Triggered by session_start().
- read() : string
- Read a session stored in DynamoDB.
- register() : bool
- Register the DynamoDB session handler.
- write() : bool
- Write a session to DynamoDB.
Methods
__construct()
public
__construct(SessionConnectionInterface $connection) : mixed
Parameters
- $connection : SessionConnectionInterface
close()
Close a session from writing.
public
close() : bool
Return values
bool —Success
destroy()
Delete a session stored in DynamoDB.
public
destroy(string $id) : bool
Parameters
- $id : string
-
Session ID.
Return values
bool —Whether or not the operation succeeded.
fromClient()
Creates a new DynamoDB Session Handler.
public
static fromClient(DynamoDbClient $client[, array<string|int, mixed> $config = [] ]) : SessionHandler
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
- $client : DynamoDbClient
-
Client for doing DynamoDB operations
- $config : array<string|int, mixed> = []
-
Configuration for the Session Handler
Return values
SessionHandlergarbageCollect()
Triggers garbage collection on expired sessions.
public
garbageCollect() : mixed
Tags
gc()
Satisfies the session handler interface, but does nothing. To do garbage collection, you must manually call the garbageCollect() method.
public
gc(int $maxLifetime) : bool
Parameters
- $maxLifetime : int
-
Ignored.
Tags
Return values
bool —Whether or not the operation succeeded.
open()
Open a session for writing. Triggered by session_start().
public
open(string $savePath, string $sessionName) : bool
Parameters
- $savePath : string
-
Session save path.
- $sessionName : string
-
Session name.
Return values
bool —Whether or not the operation succeeded.
read()
Read a session stored in DynamoDB.
public
read(string $id) : string
Parameters
- $id : string
-
Session ID.
Return values
string —Session data.
register()
Register the DynamoDB session handler.
public
register() : bool
Tags
Return values
bool —Whether or not the handler was registered.
write()
Write a session to DynamoDB.
public
write(string $id, string $data) : bool
Parameters
- $id : string
-
Session ID.
- $data : string
-
Serialized session data to write.
Return values
bool —Whether or not the operation succeeded.