PHP code example of stechstudio / phpinfo

1. Go to this page and download the library: Download stechstudio/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/ */

    

stechstudio / phpinfo example snippets



// Make sure this points to your composer autoload file, if you are using plain PHP.
// If you are in a framework context, you can probably remove this line as your
// framework likely handles it for you.

use STS\Phpinfo\Info;

$info = Info::capture();

use STS\Phpinfo\Info;

// If you've saved the HTML output from phpinfo()
$info = Info::fromHtml($yourSavedHtmlOutput);

// If you've saved the CLI output from phpinfo()
$info = Info::fromText($yourSavedHtmlOutput);

// Your PHP version
$info->version(); // 8.2.0

// Check for the presence of a specific module. Name is case-insensitive.
$info->hasModule('redis'); // true

// Check to see if a specific configuration key is present. Name is case-insensitive.
$info->hasConfig('ICU version'); // true

// Retrieve the value for a specific configuration key. Name is case-insensitive. If there is both a local and master value, the local is returned as default.
$info->config('max_file_uploads'); // 5

// Pass in 'master' as a second parameter to retrieve the master value instead. Note that this will return null if there is no master value;
$info->config('max_file_uploads', 'master'); // 20
$info->config('BCMath support', 'master'); // null

// Loop over defined modules
foreach($info->modules() AS $module) {
    $module->name(); // session
    
    // Configs are grouped the same way phpinfo() groups them by table
    // Different groups have different table headers, different number of values
    foreach($module->groups() AS $group) {
        $group->headings(); // [Directive, Local Value, Master Value]
        
        foreach($group->configs() AS $config) {
            $config->name(); // session.gc_maxlifetime
            $config->localValue(); // 1440
            
            $config->hasMasterValue(); // True (will be false if there is only one value)
            $config->masterValue(); // 28800
        }
    }
}

// This flattens the grouped 'session' configs down to a single collection
$info->module('session')->configs();

// This flattens ALL configs across all modules down to a single collection
$info->configs();

// This lookup is case-insensitive. Will return null if no matching module is found.
$module = $info->module('zend opcache');

// Retrieve the name of the module as displayed in phpinfo(), which might have a different case.
$module->name(); // Zend OPcache

// Flatten all configs into one collection. You can then use any Laravel collection method.
$module->configs()->count(); // 59

// Retrieve a specific configuration from this module. This works exactly the same as the main `config()` method shown in the previous section.
$module->config('Max keys'); // 16229
$module->config('opcache.enable_file_override', 'master'); // Off

// Retrieve just the first group of configs, which is often the list of single-value configs
$group = $info->module('session')->groups()->first(); // Collection of Configs

foreach ($info->modules() AS $module) {
    echo '<h2>' . $module->name() . '</h2>';

    echo '<ul>';
    foreach($module->configs() AS $config) {
        echo '<li>';
        echo $config->name() . ': ' . $config->value();
        if($config->hasMasterValue()) {
            echo ' (master: ' . $config->masterValue() . ')';
        }
        echo '</li>';
    }
    echo '</ul>';
}