PHP code example of cyberline / systemd-state

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

    

cyberline / systemd-state example snippets


# get info about systemd itself:
$systemdState = new SystemdState;
$info = $systemdState->getSystemdInfo();
...

# get info about specific services:
$systemdState = new SystemdState;
$systemdState
    ->addCheckUnit('nginx');
    ->addCheckUnit('redis');
$info = $systemdState->getReport();
...

# get info from pregenerated file
# /bin/systemctl show * --no-pager > systemd.txt
$systemdState = new SystemdState;
$info = $systemdState
    ->checkFromString(file_get_contents('systemd.txt'))
    ->getReport();
...

# get info about all services:
$systemdState = new SystemdState;
$systemdState->addAllUnits();
$info = $systemdState->getReport();