PHP code example of hughcube / phpinfo

1. Go to this page and download the library: Download hughcube/phpinfo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hughcube / phpinfo example snippets


use Hughcube\PhpInfo\PhpInfo;

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

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();

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;
    }
};

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);