FileSessionStore implements SessionStoreInterface
File-based session store.
Stores each session as a file named by the RFC4122 UUID, with the payload. gc() scans the whole directory, so its cost grows with the number of sessions.
Table of Contents
Interfaces
Constants
- WINDOWS_MOVE_BUDGET_NS : mixed = 1000000000
Properties
- $clock : ClockInterface
- $directory : string
- $logger : LoggerInterface
- $ttl : int
Methods
- __construct() : mixed
- destroy() : bool
- Destroy a session.
- exists() : bool
- Check if a session exists.
- gc() : array<string|int, Uuid>
- Remove sessions older than the configured TTL, along with the temporary files of writes that never made it into place and the lock files a {@see FileSessionLock} in the same directory left behind.
- read() : string|false
- Read session data.
- write() : bool
- Write session data.
- deleteExpiredLockFile() : void
- Unlinks the file only while holding its lock: a request that holds the lock keeps its file however long it runs, and one waiting for it notices the file is gone once it gets the lock, see {@see FileSessionLock}.
- isLockFile() : bool
- isTemporaryFile() : bool
- moveIntoPlace() : bool
- pathFor() : string
Constants
WINDOWS_MOVE_BUDGET_NS
private
mixed
WINDOWS_MOVE_BUDGET_NS
= 1000000000
Properties
$clock read-only
private
ClockInterface
$clock
= new NativeClock()
$directory read-only
private
string
$directory
$logger read-only
private
LoggerInterface
$logger
= new NullLogger()
$ttl read-only
private
int
$ttl
= 3600
Methods
__construct()
public
__construct(string $directory[, int $ttl = 3600 ][, ClockInterface $clock = new NativeClock() ][, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
- $directory : string
- $ttl : int = 3600
- $clock : ClockInterface = new NativeClock()
- $logger : LoggerInterface = new NullLogger()
destroy()
Destroy a session.
public
destroy(Uuid $id) : bool
Parameters
- $id : Uuid
-
The session ID being destroyed. The return value (usually TRUE on success, FALSE on failure).
Return values
boolexists()
Check if a session exists.
public
exists(Uuid $id) : bool
Parameters
- $id : Uuid
-
the session id
Return values
bool —true if the session exists, false otherwise
gc()
Remove sessions older than the configured TTL, along with the temporary files of writes that never made it into place and the lock files a {@see FileSessionLock} in the same directory left behind.
public
gc() : array<string|int, Uuid>
Returns an array of deleted session IDs (UUID instances).
Return values
array<string|int, Uuid>read()
Read session data.
public
read(Uuid $id) : string|false
Returns an encoded string of the read data. If nothing was read, it must return false.
Parameters
- $id : Uuid
-
the session id to read data for
Return values
string|falsewrite()
Write session data.
public
write(Uuid $id, string $data) : bool
Parameters
- $id : Uuid
-
the session id
- $data : string
-
the encoded session data
Return values
booldeleteExpiredLockFile()
Unlinks the file only while holding its lock: a request that holds the lock keeps its file however long it runs, and one waiting for it notices the file is gone once it gets the lock, see {@see FileSessionLock}.
private
deleteExpiredLockFile(string $path, int $now) : void
Parameters
- $path : string
- $now : int
isLockFile()
private
isLockFile(string $entry) : bool
Parameters
- $entry : string
Return values
boolisTemporaryFile()
private
isTemporaryFile(string $entry) : bool
Parameters
- $entry : string
Return values
boolmoveIntoPlace()
private
moveIntoPlace(string $tmp, string $path) : bool
Parameters
- $tmp : string
- $path : string
Return values
boolpathFor()
private
pathFor(Uuid $id) : string
Parameters
- $id : Uuid