Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

Stats
in package

FinalYes

Per-worker counter struct for Store/Counter/Pool/Subscriber observability.

Stats are PER-WORKER — each OpenSwoole worker has its own pool and its own subscriber runners, so the counts here are local to one process. For cluster-wide aggregation, poll each worker's snapshot (e.g. expose /health/stats and have Prometheus scrape every server).

Why no Atomic: stats are observability, not correctness. A lost increment under high contention is acceptable; the alternative is spending shared-memory budget on Atomic slots that we'd otherwise use for app state. Per-worker plain ints are honest about what they provide.

Table of Contents

Properties

$counters  : array<string, int>

Methods

get()  : int
Read the current value of counter $key, returning 0 when the key has never been incremented.
inc()  : void
Increment counter $key by $by (default 1). Creates the key with value $by if absent.
reset()  : void
Reset all counters to zero by discarding the internal map.
snapshot()  : array<string, int>
Return a copy of all counters as a string→int map.

Properties

$counters

private array<string, int> $counters = []

Methods

get()

Read the current value of counter $key, returning 0 when the key has never been incremented.

public get(string $key) : int
Parameters
$key : string
Return values
int

inc()

Increment counter $key by $by (default 1). Creates the key with value $by if absent.

public inc(string $key[, int $by = 1 ]) : void
Parameters
$key : string
$by : int = 1

reset()

Reset all counters to zero by discarding the internal map.

public reset() : void

snapshot()

Return a copy of all counters as a string→int map.

public snapshot() : array<string, int>
Return values
array<string, int>
On this page