Documentation

Memory extends AbstractRegistry
in package

In-memory registry class

A hermetic, single-process reference implementation of the registry contract. Because it never leaves the process it can't provide real cross-process visibility - it exists to prove the contract in tests and to serve as a fake for consumers testing against this package.

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
3.0.0

Table of Contents

Properties

$records  : array<string|int, mixed>
Records, keyed by worker ID

Methods

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

Properties

$records

Records, keyed by worker ID

protected array<string|int, mixed> $records = []

Methods

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

prune()

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
int

read()

Fetch a record by ID, or null if it isn't there

public read(string $id) : WorkerRecord|null
Parameters
$id : string
Return values
WorkerRecord|null

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

encode()

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
throws
Exception
Return values
string

isExpired()

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
bool

purgeUndecodable()

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
int

        
On this page

Search results