FileSessionLock implements SessionLockInterface
Session lock backed by `flock()` on one file per session.
Works across the processes and threads of one machine, which is what FileSessionStore serves. Lock files are not deleted on release: unlinking a file another worker has open would let a third worker lock a new file of the same name next to it. Pointed at the session directory, FileSessionStore::gc() removes the lock files of expired sessions, each only while holding its lock, and a worker that waited on a removed file opens the new one once it gets the lock.
Tags
Table of Contents
Interfaces
- SessionLockInterface
- Serializes the requests of one session across the workers that serve it.
Constants
- FILE_SUFFIX : mixed = '.lock'
- RETRY_DELAY_MICROSECONDS : mixed = 10000
Properties
- $directory : string
- $handles : array<string, resource>
- $logger : LoggerInterface
- $timeout : float
Methods
- __construct() : mixed
- acquire() : void
- Blocks until the lock of the session is held, or gives up after the implementation's timeout.
- release() : void
- tryAcquire() : bool
- Takes the lock of the session only if no other request holds it right now, without waiting.
- lock() : bool
- pathFor() : string
Constants
FILE_SUFFIX
public
mixed
FILE_SUFFIX
= '.lock'
RETRY_DELAY_MICROSECONDS
private
mixed
RETRY_DELAY_MICROSECONDS
= 10000
Properties
$directory read-only
private
string
$directory
$handles
private
array<string, resource>
$handles
= []
$logger read-only
private
LoggerInterface
$logger
= new NullLogger()
$timeout read-only
private
float
$timeout
= 30.0
Methods
__construct()
public
__construct(string $directory[, float $timeout = 30.0 ][, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
- $directory : string
- $timeout : float = 30.0
-
how long to wait for a lock held by another request, in seconds
- $logger : LoggerInterface = new NullLogger()
acquire()
Blocks until the lock of the session is held, or gives up after the implementation's timeout.
public
acquire(Uuid $sessionId) : void
Parameters
- $sessionId : Uuid
release()
public
release(Uuid $sessionId) : void
Parameters
- $sessionId : Uuid
tryAcquire()
Takes the lock of the session only if no other request holds it right now, without waiting.
public
tryAcquire(Uuid $sessionId) : bool
Parameters
- $sessionId : Uuid
Return values
bool —false when another request holds the lock
lock()
private
lock(Uuid $sessionId, float $timeout) : bool
Parameters
- $sessionId : Uuid
- $timeout : float
Return values
bool —false when another request still held the lock after $timeout seconds
pathFor()
private
pathFor(Uuid $sessionId) : string
Parameters
- $sessionId : Uuid