Redis based session handler.
More...
|
| __construct () |
| Create new instance of handler.
|
|
| abort () |
| Release lock on the session without writing it.
|
|
| close () |
| Close the session completely.
|
|
| destroy (string $id) |
| Handle destroying a session.
|
|
| gc (int $max_lifetime) |
| Garbage collect sessions.
|
|
| init () |
| Init session handler.
|
|
| kill_all_sessions () |
| Kill all active sessions, the core sessions table is purged afterwards.
|
|
| kill_session ($sid) |
| Kill one session, the session record is removed afterwards.
|
|
| open (string $path, string $name) |
| Update our session search path to include session name when opened.
|
|
| read (string $id) |
| Read the session data from storage.
|
|
| requires_write_lock () |
| Has this session been opened with a writelock? Your handler should call this during start() if you support read-only sessions.
|
|
| session_exists ($sid) |
| Check the backend contains data for this session id.
|
|
| set_requires_write_lock ($requireswritelock) |
| This is called after init() and before start() to indicate whether the session opened should be writable or not.
|
|
| start () |
| Start the session.
|
|
| write (string $id, string $data) |
| Write the serialized session data to our session store.
|
|
| write_close () |
| Write the session and release lock.
|
|
|
const | COMPRESSION_GZIP = 'gzip' |
| Compressor: PHP GZip.
|
|
const | COMPRESSION_NONE = 'none' |
| Compressor: none.
|
|
const | COMPRESSION_ZSTD = 'zstd' |
| Compressor: PHP Zstandard.
|
|
int const | MAX_RETRIES = 5 |
| Maximum number of retries for cache store operations.
|
|
|
| lock_session ($id) |
| Obtain a session lock so we are the only one using it at the moment.
|
|
| time () |
| Return the current time.
|
|
| unlock_session ($id) |
| Unlock a session.
|
|
|
int | $acquiretimeout = 120 |
| $acquiretimeout how long to wait for session lock in seconds
|
|
int | $acquirewarn = null |
| $acquirewarn how long before warning when waiting for a lock in seconds
|
|
string | $auth = '' |
| $auth redis password
|
|
bool bool | $clustermode = false |
| $clustermode Redis in cluster mode.
|
|
int | $compressor = self::COMPRESSION_NONE |
| $compressor The compressor to use
|
|
Redis RedisCluster | $connection = null |
| Connection.
|
|
int | $database = 0 |
| $database the Redis database to store sesions in
|
|
array array | $host = [] |
| $host save_path string
|
|
string | $lasthash = null |
| $lasthash hash of the session data content
|
|
int | $lockexpire |
| $lockexpire how long to wait in seconds before expiring the lock automatically so that other requests may continue execution, ignored if PECL redis is below version 2.2.0.
|
|
int | $lockretry = 100 |
| $lockretry how long to wait between session lock attempts in ms
|
|
array | $locks = array() |
| $locks List of currently held locks by this page.
|
|
int | $port = 6379 |
| $port The port to connect to
|
|
array | $prefix = '' |
| $servers list of servers parsed from save_path
|
|
boolean | $requireswritelock = false |
| $requireswritelock does the session need and/or have a lock?
|
|
int | $serializer = Redis::SERIALIZER_PHP |
| $serializer The serializer to use
|
|
array | $sslopts = [] |
| $sslopts SSL options, if applicable
|
|
int | $timeout |
| $timeout How long sessions live before expiring.
|
|
Redis based session handler.
The default Redis session handler does not handle locking in 2.2.7, so we have written a php session handler that uses locking. The places where locking is used was modeled from the memcached code that is used in Moodle https://github.com/php-memcached-dev/php-memcached/blob/master/php_memcached_session.c
- Copyright
- 2016 Russell Smith
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ abort()
core\session\handler::abort |
( |
| ) |
|
|
inherited |
Release lock on the session without writing it.
May not be possible in older versions of PHP. If so, session may be written anyway so that any locks are released.
◆ close()
core\session\redis::close |
( |
| ) |
|
Close the session completely.
We also remove all locks we may have obtained that aren't expired.
- Return values
-
bool | true on success. false on unable to unlock sessions. |
◆ destroy()
core\session\redis::destroy |
( |
string | $id | ) |
|
Handle destroying a session.
- Parameters
-
string | $id | the session id to destroy. |
- Return values
-
bool | true if the session was deleted, false otherwise. |
◆ gc()
core\session\redis::gc |
( |
int | $max_lifetime | ) |
|
Garbage collect sessions.
We don't we any as Redis does it for us.
- Parameters
-
integer | $max_lifetime | All sessions older than this should be removed. |
- Return values
-
bool | true, as Redis handles expiry for us. |
◆ init()
core\session\redis::init |
( |
| ) |
|
◆ kill_all_sessions()
core\session\redis::kill_all_sessions |
( |
| ) |
|
Kill all active sessions, the core sessions table is purged afterwards.
Reimplemented from core\session\handler.
◆ kill_session()
core\session\redis::kill_session |
( |
| $sid | ) |
|
Kill one session, the session record is removed afterwards.
- Parameters
-
Reimplemented from core\session\handler.
◆ lock_session()
core\session\redis::lock_session |
( |
| $id | ) |
|
|
protected |
Obtain a session lock so we are the only one using it at the moment.
- Parameters
-
string | $id | The session id to lock. |
- Return values
-
bool | true when session was locked, exception otherwise. |
- Exceptions
-
exception | When we are unable to obtain a session lock. |
◆ open()
core\session\redis::open |
( |
string | $path, |
|
|
string | $name ) |
Update our session search path to include session name when opened.
- Parameters
-
string | $path | unused session save path. (ignored) |
string | $name | Session name for this session. (ignored) |
- Return values
-
bool | true always as we will succeed. |
◆ read()
core\session\redis::read |
( |
string | $id | ) |
|
Read the session data from storage.
- Parameters
-
string | $id | The session id to read from storage. |
- Return values
-
string | The session data for PHP to process. |
- Exceptions
-
RedisException | when we are unable to talk to the Redis server. |
◆ requires_write_lock()
core\session\handler::requires_write_lock |
( |
| ) |
|
|
inherited |
Has this session been opened with a writelock? Your handler should call this during start() if you support read-only sessions.
- Return values
-
bool | true if session is intended to have a write lock. |
◆ session_exists()
core\session\redis::session_exists |
( |
| $sid | ) |
|
Check the backend contains data for this session id.
Note: this is intended to be called from manager\session_exists() only.
- Parameters
-
- Return values
-
bool | true if session found. |
Reimplemented from core\session\handler.
◆ set_requires_write_lock()
core\session\handler::set_requires_write_lock |
( |
| $requireswritelock | ) |
|
|
inherited |
This is called after init() and before start() to indicate whether the session opened should be writable or not.
This is intentionally captured even if your handler doesn't support non-locking sessions, so that behavior (upon session close) matches closely between handlers.
- Parameters
-
bool | $requireswritelock | true if needs to be open for writing |
◆ start()
core\session\redis::start |
( |
| ) |
|
◆ time()
core\session\redis::time |
( |
| ) |
|
|
protected |
Return the current time.
- Return values
-
int | the current time as a unixtimestamp. |
◆ unlock_session()
core\session\redis::unlock_session |
( |
| $id | ) |
|
|
protected |
Unlock a session.
- Parameters
-
string | $id | Session id to be unlocked. |
◆ write()
core\session\redis::write |
( |
string | $id, |
|
|
string | $data ) |
Write the serialized session data to our session store.
- Parameters
-
string | $id | session id to write. |
string | $data | session data |
- Return values
-
bool | true on write success, false on failure |
◆ write_close()
core\session\handler::write_close |
( |
| ) |
|
|
inherited |
Write the session and release lock.
If the session was not intentionally opened with a write lock, then we will abort the session instead if able.
The documentation for this class was generated from the following file:
- lib/classes/session/redis.php