Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

StoreSessionHandler
in package
implements SessionHandlerInterface

FinalYes

Backend-agnostic session handler — rides whichever backend Store::defaultBackend() is configured with.

  • Store::defaultBackend(Store::BACKEND_TABLE) → sessions live in OpenSwoole\Table shared 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_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).
write()  : bool
__construct()  : mixed

Constants

Properties

Methods

destroy()

public destroy(mixed $sessionId) : bool
Parameters
$sessionId : mixed
Return values
bool

gc()

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|false

open()

public open(mixed $savePath, mixed $sessionName) : bool
Parameters
$savePath : mixed
$sessionName : mixed
Return values
bool

read()

public read(mixed $sessionId) : string
Parameters
$sessionId : mixed
Return values
string

register()

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
self

write()

public write(mixed $sessionId, mixed $sessionData) : bool
Parameters
$sessionId : mixed
$sessionData : mixed
Return values
bool
On this page