Skip to content
docsv0.12.0

FileNonceLedger

A spent-nonce ledger backed by one file per nonce. Atomicity comes from the filesystem rather than from this class: `fopen(..., 'x')` creates the file only if it does not exist, and the kernel settles the race. A `file_exists()` followed by a write would read correctly in every test and lose to two shells pressing enter together — the exact case the ledger is for, since an authorization worth signing is one worth not running twice. Hosts with more than one machine want a shared implementation; this one is honest about being per-host, and per-host is the right scope for a local operator surface.

FileNonceLedger::__construct()

public function __construct(string $directory):

Parameters

Parameters of __construct()
NameTypeDescription
$directorystring

FileNonceLedger::spend()

public function spend(string $nonce, int $ttlSeconds, int $now): bool

Wins the race or loses it, decided by the kernel rather than by this method. Returns false when the directory cannot be created: unable to remember means unable to promise single use, and refusing beats granting on a promise it knows it is not keeping.

Parameters

Parameters of spend()
NameTypeDescription
$noncestring
$ttlSecondsint
$nowint