PHP code example of gemorroj / ginfo

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

    

gemorroj / ginfo example snippets



use Ginfo\Ginfo;

$ginfo = new Ginfo();

print_r($ginfo->getGeneral()); // kernel, uptime, virtualization, load, etc...
print_r($ginfo->getPhp()); // version, extensions, Opcache, FPM, APCU, etc...
print_r($ginfo->getCpu()); // cores, speed, cache, etc...
print_r($ginfo->getMemory()); // total memory, used, free, cached, swap, etc...
print_r($ginfo->getSoundCard()); // vendor, name
print_r($ginfo->getUsb()); // vendor, name, speed
print_r($ginfo->getUps()); // vendor, time, status, charge, etc...
print_r($ginfo->getPci()); // vendor, name
print_r($ginfo->getNetwork()); // name, speed, state, stats, etc...
print_r($ginfo->getDisk()); // mounts, drives, raids, size, type, stats, etc...
print_r($ginfo->getBattery()); // model, status, voltage, charge, etc...
print_r($ginfo->getSensors()); // name, value, unit, path
print_r($ginfo->getProcesses()); // name, pid, commandLine, memory, state, stats, etc...
print_r($ginfo->getServices()); // name, state, type, etc...
print_r($ginfo->getPrinters()); // name, enabled
print_r($ginfo->getSamba()); // files, services, connections, etc...
print_r($ginfo->getSelinux()); // enabled, mode, policy
print_r($ginfo->getNginx()); // version, status, etc...
print_r($ginfo->getAngie('http://localhost/status/')); // version, status, etc...
print_r($ginfo->getHttpd()); // version, status, etc...
print_r($ginfo->getCaddy()); // version, status, etc...
print_r($ginfo->getMysql(new \PDO('mysql:host=127.0.0.1', 'root', ''))); // variables, performance, status, etc...
print_r($ginfo->getPostgres(new \PDO('pgsql:host=127.0.0.1', 'postgres', 'postgres'))); // pg_stat_activity, pg_stat_statements, etc...
print_r($ginfo->getManticore(new \PDO('mysql:host=127.0.0.1;port=9306', 'root', ''))); // status, variables, etc...
print_r($ginfo->getRedis(new \Redis(['host' => '127.0.0.1', 'port' => 6379]))); // status, memory, cpu, etc...
print_r($ginfo->getSqlite(new \PDO('sqlite:/var/www/mydb.sqlite'))); // version, size, options, etc...
$memcached = new \Memcached();
$memcached->addServer('127.0.0.1', 11211);
print_r($ginfo->getMemcached($memcached)); // version, stats, etc...
print_r($ginfo->getMongo(new \MongoDB\Driver\Manager('mongodb://127.0.0.1:27017'))); // version, stats, etc...
print_r($ginfo->getElasticsearch('https://127.0.0.1:9200/_cluster/stats', 'user', 'pass'); // version, stats, etc...


use Ginfo\Ginfo;
use Ginfo\Info\InfoInterface;
use Ginfo\InfoParserInterface;

// class for parsed data
final readonly class SwooleInfo implements InfoInterface
{
    public function __construct(private array $stats)
    {
    }
    
    public function getStats(): array
    {
        return $this->stats;
    }
}

// parser
final readonly class SwooleParser implements InfoParserInterface
{
    public function run(): ?InfoInterface
    {
        $stats = \app('Swoole\Http\Server')->stats(); // laravel
        return new SwooleInfo($stats);
    }
}

$swooleParser = new SwooleParser();

$ginfo = new Ginfo(customParsers: [$swooleParser]);
/** @var SwooleInfo $data */
$data = $ginfo->getCustomParser(SwooleParser::class);
print_r($data->getStats());