-
Notifications
You must be signed in to change notification settings - Fork 0
Storage Drivers
A Storage Driver is responsible to provide an interface to deal with the storing functionality of the session:
The session data can be stored in a database, file-system, in-memory, etc. The Storage driver is responsible for communicating with these storage containers and store/fetch/destroy the session data based on the Session Identifier.
This driver is required to provide a function that destroys any session data older than some time.
The Storage Driver is responsible for providing ways to lock/unlock the session data of a given Session Identifier, so that no other process would use the same session data at the same time. The session data needs to be automatically unlocked at the end of the running process.
As the default PHP session handler, this driver uses the file-system to store the session data. It will use
the value of the ini setting session.save_path
as default directory, but you can also pass a custom path as the
first argument to the constructor. If you want a custom file prefix, pass it as the second argument to the constructor.
To use this driver, require it with composer:
composer require phpsess/file-storage
Then create an instance of it:
<?php
use PHPSess\Storage\FileStorage;
$sessionStorage = new FileStorage();
And pass the driver instance to the Session Handler.
This driver is not intended to be used in production. It uses an array to store the session data, being suitable for mocking in tests. Of course, the session data won't survive to the next request.
To use this driver, require it with composer:
composer require phpsess/mock-storage
Then create an instance of it:
<?php
use PHPSess\Storage\MockStorage;
$sessionStorage = new MockStorage();
And pass the driver instance to the Session Handler.