CoolCMS API

SettingReadProbe
in package

FinalYes

Records which `cms_system_settings` keys are really read at runtime.

Neither the code nor the database says which keys are read (SettingContext::get(), getSettings()[module][key], settings presenter constants), so without this probe keys cannot be deleted or renamed safely. It records reads of SettingContext in three kinds:

  • hit: get(module, key) found the key in the settings map (field module:key to count),
  • miss: get(module, key) did not find it (a silent fall-through to null),
  • bulk: getSettings() or get(null) read the whole map; the caller class is recorded.

Overhead: reads are aggregated in request memory and written once at the end of the request in a single Redis pipeline (HINCRBY per field plus EXPIRE). A disabled probe does nothing. IMPORTANT: no per-request write to the database or log, otherwise every request gets slower. The probe is fail-open: a Redis failure is swallowed and the first error disables writes for the rest of the request.

Storage: Redis hashes {prefix}settings:probe:hit|miss|bulk with the TTL Config::$settingsProbeTtl, renewed on each write so the data disappears after the probe is turned off. {prefix}settings:probe:since holds the time of the first write and expires together with the hashes, so a new collection gets a new start.

Enable with cache.config.settingsProbeEnabled: true in config/Shared/local.neon (disabled by default) and delete temp/cache. Read the results with php bin/settings-usage.php.

Table of Contents

Constants

KIND_BULK  : mixed = 'bulk'
KIND_HIT  : mixed = 'hit'
KIND_MISS  : mixed = 'miss'

Properties

$autoFlush  : bool
$bulk  : array<string, int>
$config  : Config
$enabled  : bool
$hits  : array<string, int>
$misses  : array<string, int>
$redis  : Client
$redisUnavailable  : bool
$shutdownRegistered  : bool

Methods

__construct()  : mixed
flush()  : void
Writes the aggregated counters to Redis in one pipeline and resets them; never throws (fail-open).
hashKey()  : string
isEnabled()  : bool
readAll()  : array{hit: array, miss: array, bulk: array, since: ?int}
Reads the collected data for `bin/settings-usage.php`. A Redis failure throws, so the tool reports it instead of pretending the data is empty.
recordBulkRead()  : void
Records a read of the whole map (the key cannot be determined); `$caller` is the calling class or file.
recordRead()  : void
Records one `get(module, key)` read; `$found` tells whether the key existed in the settings map.
sinceKey()  : string
scheduleFlush()  : void

Constants

Properties

Methods

__construct()

public __construct(Client $redis, Config $config[, bool $autoFlush = true ]) : mixed
Parameters
$redis : Client
$config : Config
$autoFlush : bool = true

true schedules the write at the end of the request (register_shutdown_function); tests pass false and call flush()

flush()

Writes the aggregated counters to Redis in one pipeline and resets them; never throws (fail-open).

public flush() : void

Public for tests and manual calls; at runtime the end of the request calls it.

hashKey()

public static hashKey(string $prefix, string $kind) : string
Parameters
$prefix : string
$kind : string
Return values
string

readAll()

Reads the collected data for `bin/settings-usage.php`. A Redis failure throws, so the tool reports it instead of pretending the data is empty.

public static readAll(Client $redis, string $prefix) : array{hit: array, miss: array, bulk: array, since: ?int}
Parameters
$redis : Client
$prefix : string
Return values
array{hit: array, miss: array, bulk: array, since: ?int}

recordBulkRead()

Records a read of the whole map (the key cannot be determined); `$caller` is the calling class or file.

public recordBulkRead(string $caller) : void
Parameters
$caller : string

recordRead()

Records one `get(module, key)` read; `$found` tells whether the key existed in the settings map.

public recordRead(int $module, string $key, bool $found) : void
Parameters
$module : int
$key : string
$found : bool

sinceKey()

public static sinceKey(string $prefix) : string
Parameters
$prefix : string
Return values
string
On this page

Search results