API Index — Namespaces, Packages, Reports, Indices
StoreSessionHandler
in package
implements
SessionHandlerInterface
Backend-agnostic session handler — rides whichever backend
Store::defaultBackend() is configured with.
Store::defaultBackend(Store::BACKEND_TABLE)→ sessions live inOpenSwoole\Tableshared memory. Single-host. Lost on restart.Store::defaultBackend(Store::BACKEND_REDIS)→ sessions live in Redis/Valkey. CROSS-NODE, persistent with AOF/RDB. The session set on server A is readable from server B. Ideal for horizontally- scaled deployments behind a sticky-or-not load balancer.Store::defaultBackend('tiered')(when wired) → L1 + L2.
Storage shape: one row per session id in the zealphp_sessions
table with data (serialised session payload) + expires_at
columns. TTL respected by Redis natively when the Redis backend's
make() declared mode => 'ttl'; for Table backend the GC sweep
inspects expires_at and deletes expired rows.
Usage: StoreSessionHandler::register(1440); // session_max_lifetime in seconds session_set_save_handler(StoreSessionHandler::instance(), true);
Table of Contents
Interfaces
- SessionHandlerInterface
Constants
- TABLE : mixed = 'zealphp_sessions'
Properties
- $instance : self|null
- $tableCreated : bool
- $ttl : int
Methods
- close() : bool
- destroy() : bool
- gc() : int|false
- Periodic sweep — relevant for the Table backend; on Redis the native TTL takes care of expiry without needing this. Returns the number of sessions deleted.
- instance() : self
- open() : bool
- read() : string
- register() : self
- Idempotent setup. Pass the session TTL in seconds (PHP's
session.gc_maxlifetimedefault is 1440). MUST be called BEFORE$app->run()so the Store table is created in the master process and inherited on fork (Table backend) or registered with the right schema for Redis (TTL mode + 'expires_at' for the Table fallback). - write() : bool
- __construct() : mixed
Constants
TABLE
private
mixed
TABLE
= 'zealphp_sessions'
Properties
$instance
private
static self|null
$instance
= null
$tableCreated
private
static bool
$tableCreated
= false
$ttl
private
static int
$ttl
= 1440
Methods
close()
public
close() : bool
Return values
booldestroy()
public
destroy(mixed $sessionId) : bool
Parameters
- $sessionId : mixed
Return values
boolgc()
Periodic sweep — relevant for the Table backend; on Redis the native TTL takes care of expiry without needing this. Returns the number of sessions deleted.
public
gc(mixed $maxlifetime) : int|false
Parameters
- $maxlifetime : mixed
Return values
int|falseinstance()
public
static instance() : self
Return values
selfopen()
public
open(mixed $savePath, mixed $sessionName) : bool
Parameters
- $savePath : mixed
- $sessionName : mixed
Return values
boolread()
public
read(mixed $sessionId) : string
Parameters
- $sessionId : mixed
Return values
stringregister()
Idempotent setup. Pass the session TTL in seconds (PHP's
session.gc_maxlifetime default is 1440). MUST be called BEFORE
$app->run() so the Store table is created in the master process
and inherited on fork (Table backend) or registered with the right
schema for Redis (TTL mode + 'expires_at' for the Table fallback).
public
static register([int $ttl = 1440 ]) : self
Parameters
- $ttl : int = 1440
Return values
selfwrite()
public
write(mixed $sessionId, mixed $sessionData) : bool
Parameters
- $sessionId : mixed
- $sessionData : mixed
Return values
bool__construct()
private
__construct() : mixed