parseMemoryLimit.php
Table of Contents
Functions
- parseMemoryLimit() : int|null
- Parses a `memory_limit`-style size into bytes, or `null` when the value names no usable ceiling.
Functions
parseMemoryLimit()
Parses a `memory_limit`-style size into bytes, or `null` when the value names no usable ceiling.
parseMemoryLimit(string $value) : int|null
Accepts a plain byte count, optionally suffixed with K, M or G
(case-insensitive), with optional surrounding whitespace — the shapes PHP itself
reads as a size. null comes back for:
-1, the value that means unlimited: there is no ceiling to report;0or a negative count, which name no usable budget;- an empty string, or anything that is not a number followed by at most one of those three suffixes.
That last case includes '128MB', and deliberately. PHP reads a quantity's
multiplier from what follows the digits, accepts only a single k, m or g
there, and warns then ignores anything else — so memory_limit = 128MB is
128 bytes to PHP, not 128 mebibytes. Returning the number this function would
like it to mean would overstate the budget by a factor of a million; returning
null says unknown, which is the one answer that cannot mislead a caller.
Parameters
- $value : string
-
The raw setting value, e.g.
'512M','1G','134217728','-1'.
Tags
Return values
int|null —The size in bytes, or null when the value names no usable ceiling.