← All updates

Engineering / Field note

PHP-FPM module names can surprise a strict parser

The valid cgi-fcgi module name shows why diagnostic parsers need separate checks for format, capture completeness and runtime requirements.

By Zyel · Published · 4 min read

A module inventory can be rejected because the inventory reader misunderstands a perfectly legitimate name. PHP-FPM provides a useful example: the historical PHP 8.3.6 source registers a module named cgi-fcgi, including the hyphen. A parser that accepts only programming-language identifiers would reject it. The practical consequence is straightforward: a failed parser cannot tell you which extensions a runtime lacks. [1]

This is a reference review dated November 30, 2026, using an older, versioned source tag to explain an established behavior. It is not a new PHP vulnerability announcement or a recommendation to install that historical release. Our examples below are original Python teaching fixtures. They do not report a customer environment, a production failure or a live PHP-FPM test.

Read the producer’s format first

PHP documents the -m option as listing built-in and loaded PHP and Zend modules. The FPM source implements its own module-listing path, prints two section headings, and emits registered module names. That gives us a concrete format to study rather than a naming convention to guess. A hyphen has not become suspicious merely because a regular expression dislikes it. [1] [2]

The first example keeps a deliberately narrow token profile: ordinary ASCII identifier-shaped names plus two explicitly reviewed names containing punctuation or a space. This is our teaching policy, not PHP’s universal extension-name grammar. Another legitimate extension may require a reviewed profile change. Recognizing a token also does not prove that a trusted executable produced it.

Example 1 — Validate a limited, explicitly reviewed token profile · Python
import re

_IDENTIFIER = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
_REVIEWED_EXCEPTIONS = {"cgi-fcgi", "Zend OPcache"}

def module_token(line):
    if type(line) is not str or not 1 <= len(line) <= 128:
        raise ValueError("invalid module token")
    if not (_IDENTIFIER.fullmatch(line)
            or line in _REVIEWED_EXCEPTIONS):
        raise ValueError("unsupported module token")
    return line

Keep structure and names separate

A useful parser knows whether it is reading the PHP section or the Zend section. It should not quietly discard a line it does not understand and then declare the remaining inventory complete. This second example requires both headings in order, preserves their separate inventories and rejects duplicate entries within a section. An empty Zend section is allowed.

The size, line and character limits below are teaching choices. They make unexpected input visible; they are not limits imposed by PHP. We accept normal Windows line endings, reject stray controls, and preserve name spelling. Expanding those rules for another producer should be a conscious compatibility decision, with saved examples of the newly supported output.

Example 2 — Parse both sections without silently filtering input · Python
def parse_module_sections(text):
    if type(text) is not str or len(text) > 65536:
        raise ValueError("invalid output size or type")
    text = text.replace("\r\n", "\n")
    if any(c != "\n" and not " " <= c <= "~" for c in text):
        raise ValueError("unsupported control or non-ASCII character")
    lines = text.split("\n")
    if len(lines) > 1024:
        raise ValueError("too many lines")
    headers = ("[PHP Modules]", "[Zend Modules]")
    sections = {header: [] for header in headers}
    current, next_header = None, 0
    for line in lines:
        if line == "":
            continue
        if line in headers:
            if next_header >= 2 or line != headers[next_header]:
                raise ValueError("unexpected section order")
            current = line
            next_header += 1
        else:
            if current is None:
                raise ValueError("data before first section")
            token = module_token(line)
            if token in sections[current]:
                raise ValueError("duplicate module in section")
            sections[current].append(token)
    if next_header != 2 or not sections[headers[0]]:
        raise ValueError("missing section or empty PHP inventory")
    return {"php": tuple(sections[headers[0]]),
            "zend": tuple(sections[headers[1]])}

A readable body still needs a usable capture

Parsing text and trusting a command result are separate decisions. A collector may supply a nonzero exit code, diagnostics or a clipped body that still happens to contain both headings. The third example therefore checks a small capture envelope before parsing. It treats diagnostics as a review condition instead of blending them into the module list.

The completeness flag must come from a collector that actually knows its output limits and transport behavior. Writing true beside a truncated string cannot repair it. This function consumes already captured data; it launches no process. A real integration must separately bind the capture to its intended executable, arguments, configuration and observation time.

Example 3 — Reject failed, incomplete or diagnostic-bearing captures · Python
def consume_capture(record):
    fields = {"stdout", "stderr", "exit_code", "stdout_complete"}
    if type(record) is not dict or set(record) != fields:
        raise ValueError("unexpected capture envelope")
    if type(record["exit_code"]) is not int:
        raise ValueError("invalid exit-code type")
    if record["exit_code"] != 0:
        raise ValueError("command did not succeed")
    if record["stdout_complete"] is not True:
        raise ValueError("capture completeness not established")
    if type(record["stderr"]) is not str or record["stderr"] != "":
        raise ValueError("diagnostic output needs review")
    return parse_module_sections(record["stdout"])

Report the question you actually answered

Once parsing succeeds, a requirement check can compare exact names in the PHP section with an explicit requirement list. PHP’s get_loaded_extensions documentation describes regular and Zend extension lists separately. Preserving that distinction avoids casually treating the two inventories as interchangeable. Here, an absent requirement means absent from this accepted synthetic inventory. [3]

Example 4 — Assess named requirements without asserting application readiness · Python
def check_requirements(inventory, required):
    if type(required) not in (tuple, list) or not required:
        raise ValueError("supply an explicit nonempty requirement list")
    required = tuple(module_token(name) for name in required)
    if len(set(required)) != len(required):
        raise ValueError("duplicate requirement")
    missing = sorted(set(required) - set(inventory["php"]))
    return {
        "inventory": "parsed",
        "required_modules_present": not missing,
        "missing": missing,
        "request_sapi": "not_assessed",
        "application_ready": "not_assessed",
    }

The result deliberately leaves request SAPI and application readiness unassessed. PHP documents cli and fpm-fcgi as interface identifiers, while the cgi-fcgi module name is a different field in the FPM source. Finding that module string is not a substitute for observing the interface used by an application request. Likewise, a listed database extension does not establish a successful database connection. [1] [4]

Keep unknown distinct from missing

The final example puts the pieces together using a fictional saved capture. One requirement is present; another is absent. When the same body is marked incomplete, the result changes to unusable and the missing field becomes null. That distinction gives an operator a sensible next action: review the capture before changing the runtime.

Example 5 — Preserve the difference between absent and unassessed · Python
def assess_capture(record, required):
    try:
        inventory = consume_capture(record)
    except ValueError:
        return {"inventory": "unusable", "missing": None,
                "application_ready": "not_assessed"}
    return check_requirements(inventory, required)

# Synthetic saved output: deliberately not a real host inventory.
fixture = {
    "stdout": "[PHP Modules]\nCore\ncgi-fcgi\njson\n\n[Zend Modules]\n",
    "stderr": "", "exit_code": 0, "stdout_complete": True,
}
present = assess_capture(fixture, ["json"])
absent = assess_capture(fixture, ["pdo_mysql"])
uncertain = assess_capture(
    {**fixture, "stdout_complete": False}, ["pdo_mysql"])
assert present["required_modules_present"] is True
assert absent["missing"] == ["pdo_mysql"]
assert uncertain["missing"] is None

Run the five blocks together, in order, in Python 3. They exercise parsing and reporting only. Review malformed headings, unexpected tokens, duplicate names, incomplete captures and failed commands alongside the successful fixture. If a parser rejects real output, retain the actual diagnostic and establish the cause before widening its rules. Compatibility work is most useful when it improves observation without manufacturing certainty.

Sources + further reading

Source dates describe the original material. Publication above is the date this Zyel article went live.

  1. PHP 8.3.6 FPM source: module registration and -m outputThe PHP Group · Checked Nov 30, 2026
  2. PHP command-line optionsThe PHP Group · Checked Nov 30, 2026
  3. get_loaded_extensionsThe PHP Group · Checked Nov 30, 2026
  4. php_sapi_nameThe PHP Group · Checked Nov 30, 2026

Reader discussion

What would you ask next?

Questions, useful corrections and thoughtful disagreement are welcome. Comments are reviewed before they appear.

No reader comments yet.

10–2,000 characters. Plain text. Leave out passwords, private project data and personal contact details. A blank display name appears as Anonymous.

Complete the CAPTCHA before sending. Verification runs on your device.