Oihana PHP System

MemcachedStats uses ConstantsTrait

Enumeration of string keys returned by the `Memcached::getStats()` method.

This class defines constants that correspond to statistical property names reported by a Memcached server. These stats provide insight into server performance, memory usage, connection counts, command success rates, and more.

Purpose:

  • Prevent typos when accessing stats via $stats['some_key']
  • Improve readability and IDE autocompletion
  • Facilitate filtering, logging, or reporting on selected metrics

Example:

use oihana\enums\MemcachedStats;

$stats = $memcached->getStats();
$uptime = $stats['localhost:11211'][MemcachedStats::UPTIME] ?? 0;

Categories:

  • General Server Info (e.g. PID, version, uptime)
  • Connection Stats (e.g. current/total connections)
  • Command Stats (e.g. get/set hits/misses)
  • Network I/O Stats (e.g. bytes read/written)
  • Memory & Storage (e.g. item count, evictions, memory limit)
Tags
see
https://github.com/memcached/memcached/wiki/Commands#stats
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

BYTES  = 'bytes'
The number of bytes of data currently stored in the cache.
BYTES_READ  = 'bytes_read'
The total number of bytes read by the server over the network.
BYTES_WRITTEN  = 'bytes_written'
The total number of bytes written by the server over the network.
CAS_BADVAL  = 'cas_badval'
The number of "compare-and-set" requests that failed because the item's value was modified by another client.
CAS_HITS  = 'cas_hits'
The number of "compare-and-set" requests that succeeded.
CAS_MISSES  = 'cas_misses'
The number of "compare-and-set" requests that failed because the item was not found.
CMD_FLUSH  = 'cmd_flush'
The total number of "flush" commands executed.
CMD_GET  = 'cmd_get'
The total number of "get" commands executed.
CMD_SET  = 'cmd_set'
The total number of "set" commands executed.
CMD_TOUCH  = 'cmd_touch'
The total number of "touch" commands executed (to update item expiry).
CONNECTION_STRUCTURES  = 'connection_structures'
The number of connection structures allocated.
CURR_CONNECTIONS  = 'curr_connections'
The number of connections currently open.
CURR_ITEMS  = 'curr_items'
The number of items currently stored in the cache.
DECR_HITS  = 'decr_hits'
The number of "decrement" requests that found an item.
DECR_MISSES  = 'decr_misses'
The number of "decrement" requests that did not find an item.
DELETE_HITS  = 'delete_hits'
The number of "delete" requests that found and deleted an item.
DELETE_MISSES  = 'delete_misses'
The number of "delete" requests that did not find the item to delete.
EVICTIONS  = 'evictions'
The number of items that have been evicted from the cache due to memory limits.
GET_HITS  = 'get_hits'
The number of "get" requests that found an item in the cache.
GET_MISSES  = 'get_misses'
The number of "get" requests that did not find an item in the cache.
INCR_HITS  = 'incr_hits'
The number of "increment" requests that found an item.
INCR_MISSES  = 'incr_misses'
The number of "increment" requests that did not find an item.
LIB_EVENT  = 'libevent'
The version of the libevent library used (if applicable).
LIMIT_MAX_BYTES  = 'limit_maxbytes'
The maximum size allocated for storing items in bytes.
PID  = 'pid'
The process ID (PID) of the Memcached server.
POINTER_SIZE  = 'pointer_size'
The size of system pointers (typically 32 or 64).
RECLAIMED  = 'reclaimed'
The number of items whose space has been reclaimed (e.g., due to expiry or purging).
RESERVED_FDS  = 'reserved_fds'
The number of file descriptors reserved.
RUSAGE_SYSTEM_MICROSECONDS  = 'rusage_system_microseconds'
System CPU time used by the Memcached process in microseconds.
RUSAGE_SYSTEM_SECONDS  = 'rusage_system_seconds'
System CPU time used by the Memcached process in seconds.
RUSAGE_USER_MICROSECONDS  = 'rusage_user_microseconds'
User CPU time used by the Memcached process in microseconds.
RUSAGE_USER_SECONDS  = 'rusage_user_seconds'
User CPU time used by the Memcached process in seconds.
SLABS_MOVED  = 'slabs_moved'
(Less common) Number of times a slab has been moved.
THREADS  = 'threads'
The number of worker threads configured for Memcached.
TIME  = 'time'
The current Unix timestamp on the Memcached server.
TOTAL_CONNECTIONS  = 'total_connections'
The total number of connections established since the server started.
TOTAL_ITEMS  = 'total_items'
The total number of items that have been stored in the cache since server start.
UPTIME  = 'uptime'
The time in seconds that the Memcached server has been running.
VERSION  = 'version'
The version of the Memcached software.

Properties

$ALL  : array<string|int, mixed>|null
The list of all constants.
$CONSTANTS  : array<string|int, mixed>|null
The flipped list of all constants.

Methods

enums()  : array<string|int, mixed>
Returns an array of all constants in this enumeration.
get()  : mixed
Returns a valid enumeration value or the default value.
getAll()  : array<string, string>
Returns an array of constants in this class.
getConstant()  : string|array<string|int, string>|null
Returns the constant name(s) associated with the given value.
getGroups()  : array<string|int, string>
Returns the list of defined stat categories.
groupByCategory()  : array<string, array<string|int, string>>
Returns all stat keys grouped by category.
includes()  : bool
Checks if a given value is valid (exists as a constant in this class).
resetCaches()  : void
Reset the internal cache of the static methods.
validate()  : void
Validates if the passed-in value is a valid element in the current enum.

Constants

BYTES

The number of bytes of data currently stored in the cache.

public string BYTES = 'bytes'

BYTES_READ

The total number of bytes read by the server over the network.

public string BYTES_READ = 'bytes_read'

BYTES_WRITTEN

The total number of bytes written by the server over the network.

public string BYTES_WRITTEN = 'bytes_written'

CAS_BADVAL

The number of "compare-and-set" requests that failed because the item's value was modified by another client.

public string CAS_BADVAL = 'cas_badval'

CAS_HITS

The number of "compare-and-set" requests that succeeded.

public string CAS_HITS = 'cas_hits'

CAS_MISSES

The number of "compare-and-set" requests that failed because the item was not found.

public string CAS_MISSES = 'cas_misses'

CMD_FLUSH

The total number of "flush" commands executed.

public string CMD_FLUSH = 'cmd_flush'

CMD_GET

The total number of "get" commands executed.

public string CMD_GET = 'cmd_get'

CMD_SET

The total number of "set" commands executed.

public string CMD_SET = 'cmd_set'

CMD_TOUCH

The total number of "touch" commands executed (to update item expiry).

public string CMD_TOUCH = 'cmd_touch'

CONNECTION_STRUCTURES

The number of connection structures allocated.

public string CONNECTION_STRUCTURES = 'connection_structures'

CURR_CONNECTIONS

The number of connections currently open.

public string CURR_CONNECTIONS = 'curr_connections'

CURR_ITEMS

The number of items currently stored in the cache.

public string CURR_ITEMS = 'curr_items'

DECR_HITS

The number of "decrement" requests that found an item.

public string DECR_HITS = 'decr_hits'

DECR_MISSES

The number of "decrement" requests that did not find an item.

public string DECR_MISSES = 'decr_misses'

DELETE_HITS

The number of "delete" requests that found and deleted an item.

public string DELETE_HITS = 'delete_hits'

DELETE_MISSES

The number of "delete" requests that did not find the item to delete.

public string DELETE_MISSES = 'delete_misses'

EVICTIONS

The number of items that have been evicted from the cache due to memory limits.

public string EVICTIONS = 'evictions'

GET_HITS

The number of "get" requests that found an item in the cache.

public string GET_HITS = 'get_hits'

GET_MISSES

The number of "get" requests that did not find an item in the cache.

public string GET_MISSES = 'get_misses'

INCR_HITS

The number of "increment" requests that found an item.

public string INCR_HITS = 'incr_hits'

INCR_MISSES

The number of "increment" requests that did not find an item.

public string INCR_MISSES = 'incr_misses'

LIB_EVENT

The version of the libevent library used (if applicable).

public string LIB_EVENT = 'libevent'

LIMIT_MAX_BYTES

The maximum size allocated for storing items in bytes.

public string LIMIT_MAX_BYTES = 'limit_maxbytes'

PID

The process ID (PID) of the Memcached server.

public string PID = 'pid'

POINTER_SIZE

The size of system pointers (typically 32 or 64).

public string POINTER_SIZE = 'pointer_size'

RECLAIMED

The number of items whose space has been reclaimed (e.g., due to expiry or purging).

public string RECLAIMED = 'reclaimed'

RESERVED_FDS

The number of file descriptors reserved.

public string RESERVED_FDS = 'reserved_fds'

RUSAGE_SYSTEM_MICROSECONDS

System CPU time used by the Memcached process in microseconds.

public string RUSAGE_SYSTEM_MICROSECONDS = 'rusage_system_microseconds'

RUSAGE_SYSTEM_SECONDS

System CPU time used by the Memcached process in seconds.

public string RUSAGE_SYSTEM_SECONDS = 'rusage_system_seconds'

RUSAGE_USER_MICROSECONDS

User CPU time used by the Memcached process in microseconds.

public string RUSAGE_USER_MICROSECONDS = 'rusage_user_microseconds'

RUSAGE_USER_SECONDS

User CPU time used by the Memcached process in seconds.

public string RUSAGE_USER_SECONDS = 'rusage_user_seconds'

SLABS_MOVED

(Less common) Number of times a slab has been moved.

public string SLABS_MOVED = 'slabs_moved'

THREADS

The number of worker threads configured for Memcached.

public string THREADS = 'threads'

TIME

The current Unix timestamp on the Memcached server.

public string TIME = 'time'

TOTAL_CONNECTIONS

The total number of connections established since the server started.

public string TOTAL_CONNECTIONS = 'total_connections'

TOTAL_ITEMS

The total number of items that have been stored in the cache since server start.

public string TOTAL_ITEMS = 'total_items'

UPTIME

The time in seconds that the Memcached server has been running.

public string UPTIME = 'uptime'

VERSION

The version of the Memcached software.

public string VERSION = 'version'

Properties

$ALL

The list of all constants.

protected static array<string|int, mixed>|null $ALL = null

$CONSTANTS

The flipped list of all constants.

protected static array<string|int, mixed>|null $CONSTANTS = null

Methods

enums()

Returns an array of all constants in this enumeration.

public static enums([int $flags = SORT_STRING ]) : array<string|int, mixed>
Parameters
$flags : int = SORT_STRING

The optional second parameter flags may be used to modify the comparison behavior using these values: Comparison type flags:

  • SORT_REGULAR - compare items normally (don't change types)
  • SORT_NUMERIC - compare items numerically
  • SORT_STRING - compare items as strings
  • SORT_LOCALE_STRING - compare items as strings, based on the current locale.
Return values
array<string|int, mixed>

get()

Returns a valid enumeration value or the default value.

public static get(mixed $value[, mixed|null $default = null ]) : mixed
Parameters
$value : mixed
$default : mixed|null = null

getAll()

Returns an array of constants in this class.

public static getAll() : array<string, string>
Return values
array<string, string>

getConstant()

Returns the constant name(s) associated with the given value.

public static getConstant(string $value[, string|array<string|int, string>|null $separator = null ]) : string|array<string|int, string>|null

This method searches the class constants for one or multiple constants whose value matches (or contains) the provided value.

If the constant values are strings containing multiple parts separated by one or more separators, it splits them accordingly before matching.

The method returns:

  • a string with the constant name if exactly one constant matches,
  • an array of constant names if multiple constants share the same value,
  • or null if no constant matches the given value.

The internal cache is used to optimize repeated lookups.

Parameters
$value : string

The value to search for among the constants.

$separator : string|array<string|int, string>|null = null

Optional separator(s) to split constant values before matching.

  • If null, no splitting is performed.
  • If a string, it is used as the delimiter.
  • If an array of strings, each separator is applied iteratively.
Return values
string|array<string|int, string>|null

The constant name(s) matching the value, or null if none found.

getGroups()

Returns the list of defined stat categories.

public static getGroups() : array<string|int, string>
Tags
example
foreach (MemcachedStats::getGroups() as $group)
{
    echo strtoupper( $group ) . PHP_EOL;
    foreach (MemcachedStats::groupByCategory()[$group] as $statKey)
    {
       echo "  • $statKey" . PHP_EOL;
   }
}
Return values
array<string|int, string>

groupByCategory()

Returns all stat keys grouped by category.

public static groupByCategory() : array<string, array<string|int, string>>
Return values
array<string, array<string|int, string>>

An associative array where keys are category names and values are arrays of constant values.

includes()

Checks if a given value is valid (exists as a constant in this class).

public static includes(mixed $value[, bool $strict = false ][, string|null $separator = null ]) : bool
Parameters
$value : mixed
$strict : bool = false

[optional]

If the third parameter strict is set to true then the in_array function will also check the types of the needle in the haystack.

$separator : string|null = null

The optional string separator if the constant value contains multiple values in a single string expression.

Return values
bool

True if the value exist, False otherwise.

resetCaches()

Reset the internal cache of the static methods.

public static resetCaches() : void

validate()

Validates if the passed-in value is a valid element in the current enum.

public static validate(mixed $value[, bool $strict = true ][, string|null $separator = null ]) : void
Parameters
$value : mixed
$strict : bool = true

[optional]

If the third parameter strict is set to true then the in_array function will also check the types of the needle in the haystack.

$separator : string|null = null

The optional string separator if the constant value contains multiple values in a single string expression.

Tags
throws
ConstantException

Thrown when the passed-in value is not a valid constant.


        
On this page

Search results