Search by

hughcube / phpinfo

hughcube

Restore phpinfo() plain text in CLI/Swoole/Workerman into 1:1 pixel-perfect native HTML across PHP versions.

Package info

github.com/hughcube/phpinfo

pkg:composer/hughcube/phpinfo

Statistics

Installs: 3 192

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-27 03:38 UTC

README

Restore phpinfo() plain text output in CLI, Swoole, Workerman, and RoadRunner into 1:1 pixel-perfect native HTML across PHP versions.

Build Status Latest Stable Version PHP Version Support Total Downloads License

English | ็ฎ€ไฝ“ไธญๆ–‡

๐Ÿ’ก Why This Package?

In PHP core (ext/standard/info.c), whether phpinfo() outputs formatted HTML or plain text is dictated by an internal SAPI structure member: sapi_module.phpinfo_as_text:

  • Web SAPIs (FPM, Apache mod_php, cli-server): phpinfo_as_text = 0 (outputs full HTML tables with official CSS styling and inline logos).
  • CLI SAPIs (CLI, Swoole HTTP server, Workerman, RoadRunner): phpinfo_as_text = 1 (outputs plain text key => value lists).

When building microservices or APIs with Swoole, Workerman, or Laravel Octane, developers often expose an internal /phpinfo management endpoint. However, calling phpinfo() in these environments outputs unreadable, unstyled raw text.

hughcube/phpinfo solves this by capturing the CLI output stream and parsing it through an in-memory AST state machine, reassembling it into the exact 1:1 pixel-perfect native HTML matching the active runtime PHP version.

๐ŸŒŸ Key Features

  • โšก Auto Environment Detection: Intelligently senses if the current SAPI natively outputs HTML (e.g. FPM, Apache).
  • ๐Ÿ”„ Adaptive Zero-Overhead Output:
    • Under FPM / Apache / cli-server: passes through native HTML directly (100% byte fidelity, zero overhead).
    • Under Swoole / Workerman / RoadRunner / CLI: captures and reconstructs 1:1 styled HTML.
  • ๐ŸŽจ Version-Accurate Theme Engine:
    • Faithfully reproduces official PHP stylesheets from PHP 5.3 up to PHP 8.5+.
    • Supports PHP 8.2+ native Dark Mode (prefers-color-scheme: dark), Sticky Table Headers, and official Base64-encoded PHP & Zend logos.
  • ๐Ÿ›ก๏ธ 100% Pure Memory AST Parser:
    • No subprocesses, no proc_open/exec calls, completely immune to disable_functions restrictions.
  • ๐Ÿงช Broad Compatibility: Tested and verified across all PHP versions: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5].

๐Ÿ“ฆ Installation

composer require hughcube/phpinfo

๐Ÿš€ Quick Start

1. Adaptive HTML Output (Recommended)

use Hughcube\PhpInfo\PhpInfo;

// Automatically detects environment: passes through native HTML on FPM, restores 1:1 HTML on Swoole/CLI
$html = PhpInfo::html();

2. Swoole HTTP Server

use Hughcube\PhpInfo\PhpInfo;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

$server = new Server('0.0.0.0', 9501);

$server->on('request', function (Request $request, Response $response) {
    if ($request->server['request_uri'] === '/phpinfo') {
        $response->header('Content-Type', 'text/html; charset=utf-8');
        $response->end(PhpInfo::html());
        return;
    }

    $response->end('OK');
});

$server->start();

3. Workerman / Webman

use Hughcube\PhpInfo\PhpInfo;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;

$worker->onMessage = function (TcpConnection $connection, Request $request) {
    if ($request->path() === '/phpinfo') {
        $connection->send(new Response(200, [
            'Content-Type' => 'text/html; charset=utf-8',
        ], PhpInfo::html()));
        return;
    }
};

4. Advanced Options

use Hughcube\PhpInfo\PhpInfo;

// Check if current runtime natively outputs HTML
if (PhpInfo::supportsNativeHtml()) {
    // FPM / Apache
}

// Force pure PHP parsing & rendering (even in FPM)
$html = PhpInfo::forceRender();

// Force rendering with specific version style (e.g., PHP 8.2 Dark Mode)
$darkHtml = PhpInfo::forceRender(INFO_ALL, '8.2');

// Render HTML fragment only (<table> tables without <html>, <head>, <body> tags)
$tablesOnly = PhpInfo::forceRender(INFO_ALL, null, true);

๐Ÿ“Š Compatibility Matrix

PHP Version Theme Applied Dark Mode Sticky Headers Official Logos
< 5.6 PHP 5.6 Theme โŒ โŒ โœ…
5.6 ~ 7.0 PHP 5.6 Theme โŒ โŒ โœ…
7.0 ~ 7.4 PHP 7.0 Theme โŒ โŒ โœ…
7.4 ~ 8.2 PHP 7.4 Theme โŒ โŒ โœ…
8.2 ~ 8.4 PHP 8.2 Theme โœ… โŒ โœ…
8.4 ~ 8.5 PHP 8.4 Theme โœ… โœ… โœ…
> 8.5 PHP 8.5 Theme โœ… โœ… โœ…

๐Ÿงช Testing

composer test

๐Ÿ“„ License

The MIT License (MIT). Please see LICENSE for more information.