File
extends AbstractRegistry
in package
File registry class
One JSON file per worker, in a single flat folder.
Tags
Table of Contents
Properties
- $folder : string
- Folder holding the record files
Methods
- __construct() : mixed
- Constructor
- all() : array<string|int, mixed>
- Fetch every stored record, keyed by worker ID
- delete() : void
- Remove a record. A no-op if the ID isn't there.
- getFolder() : string
- Get the folder
- prune() : int
- Remove every record whose heartbeat is older than the given number of seconds, plus any stored entry that can no longer be decoded, returning how many were removed in total.
- read() : WorkerRecord|null
- Fetch a record by ID, or null if it isn't there
- write() : void
- Store a record, replacing any existing record with the same ID
- decode() : WorkerRecord|null
- Decode a stored record, or null if the payload is unusable
- encode() : string
- Encode a record for storage
- isExpired() : bool
- Whether a record's heartbeat is older than the given number of seconds. Shared by every backend's prune() so the cutoff rule can't drift between them.
- purgeUndecodable() : int
- Remove stored entries that can no longer be decoded into a WorkerRecord, returning how many were removed.
- readRecord() : WorkerRecord|null
- Read and decode a record file, or null if it is unreadable or unusable
- recordFiles() : array<string|int, mixed>
- The record filenames in the folder
- recordPath() : string
- Path of the file backing a given worker ID
Properties
$folder
Folder holding the record files
protected
string
$folder
Methods
__construct()
Constructor
public
__construct(string $folder) : mixed
Parameters
- $folder : string
Tags
all()
Fetch every stored record, keyed by worker ID
public
all() : array<string|int, mixed>
Return values
array<string|int, mixed>delete()
Remove a record. A no-op if the ID isn't there.
public
delete(string $id) : void
Parameters
- $id : string
getFolder()
Get the folder
public
getFolder() : string
Return values
stringprune()
Remove every record whose heartbeat is older than the given number of seconds, plus any stored entry that can no longer be decoded, returning how many were removed in total.
public
prune(int $olderThanSeconds) : int
Concrete here rather than per-backend: the expiry half is expressible purely in terms of all()/delete()/isExpired(), and four byte-identical copies would be four places for the rule to drift.
Parameters
- $olderThanSeconds : int
Return values
intread()
Fetch a record by ID, or null if it isn't there
public
read(string $id) : WorkerRecord|null
Parameters
- $id : string
Return values
WorkerRecord|nullwrite()
Store a record, replacing any existing record with the same ID
public
write(WorkerRecord $record) : void
Parameters
- $record : WorkerRecord
decode()
Decode a stored record, or null if the payload is unusable
protected
decode(string|null $payload) : WorkerRecord|null
Parameters
- $payload : string|null
Return values
WorkerRecord|nullencode()
Encode a record for storage
protected
encode(WorkerRecord $record) : string
JSON, deliberately - registry records are plain scalars and arrays, so this carries none of the unserialize() object-injection surface that job payloads do.
Parameters
- $record : WorkerRecord
Tags
Return values
stringisExpired()
Whether a record's heartbeat is older than the given number of seconds. Shared by every backend's prune() so the cutoff rule can't drift between them.
protected
isExpired(WorkerRecord $record, int $olderThanSeconds) : bool
Parameters
- $record : WorkerRecord
- $olderThanSeconds : int
Return values
boolpurgeUndecodable()
Remove stored entries that can no longer be decoded into a WorkerRecord, returning how many were removed.
protected
purgeUndecodable() : int
These are invisible to all() by design (it skips them so one corrupt entry cannot derail enumeration), which would otherwise make them permanently unreapable - a truncated write or a bad payload would leak for the lifetime of the store. Backends with real storage override this; the default is a no-op for backends that cannot hold an undecodable entry.
Return values
intreadRecord()
Read and decode a record file, or null if it is unreadable or unusable
protected
readRecord(string $path) : WorkerRecord|null
The false-check is what keeps an unreadable file on the same graceful path as an undecodable one. file_get_contents() returns false, not '', when the read itself fails - and a worker registry is read while other workers are pruning it, so a file that passes file_exists() and is then unlinked before the read lands is an ordinary race, not corruption. Under declare(strict_types=1) handing that false to decode(?string) would be a TypeError, turning a routine race into a crash that takes out enumeration for every other worker in the registry.
Parameters
- $path : string
Return values
WorkerRecord|nullrecordFiles()
The record filenames in the folder
protected
recordFiles() : array<string|int, mixed>
Return values
array<string|int, mixed>recordPath()
Path of the file backing a given worker ID
protected
recordPath(string $id) : string
IDs contain ':' and hostnames may contain '.', so the filename is a sanitized form. The sanitized form alone is not injective ('a.b' and 'a_b' both map to 'a_b'), so a short hash of the original ID is appended to keep distinct IDs in distinct files while the readable part stays useful for anyone browsing the folder.
Parameters
- $id : string