Download the PHP package joby/smol-session without Composer
On this page you can find all versions of the php package joby/smol-session. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joby/smol-session
More information about joby/smol-session
Files in joby/smol-session
Package smol-session
Short Description An opinionated PHP session management library, designed to expose a simple API but provide smart performance optimizations and minimize session creation and locking.
License MIT
Informations about the package smol-session
smolSession
An opinionated PHP session management library designed to expose a simple API while providing smart performance optimizations and minimizing session creation and locking.
Features
- Lazy session creation - Sessions are only started when data is actually written, avoiding unnecessary cookie traffic
- Minimized locking - Sessions are only locked once on first read, and again if necessary during commits, not for the entire response lifecycle
- Atomic updates - Operations like increments that apply atomically on commit are possible
- Simple static API - Clean, straightforward interface for common session operations
Installation
Usage
Typed Getters
smolSession provides type-safe getter methods that automatically convert session values to the expected type:
Type Conversion Rules
Values are converted pretty permissively using (https://github.com/joby-lol/smol-cast)[smolCast], see its readme for detailed rules about what can be converted and how it works.
How It Works
- Reading -
Session::get()reads from a cached copy of the session and applies any queued updates - Writing -
Session::set(),Session::increment(), andSession::unset()queue changes without opening the session - Committing -
Session::commit()opens the session, applies all updates atomically, and closes it
This approach minimizes session file locking and reduces the window where concurrent requests might conflict.
Advanced: Custom Atomic Updates
You can create custom atomic update operations by implementing the SessionUpdate interface:
The isAbsolute() method indicates whether the update replaces the value entirely (like SetValue) or depends on the current value (like IncrementValue). Absolute updates enable performance optimizations by discarding previous queued updates for the same key.
Requirements
Fully tested on PHP 8.3+, static analysis for PHP 8.1.
License
MIT License - See LICENSE file for details.