You are here

public function MetricService::getPhpInfoAsArray in Drupalmonitor 8

Get PHP Info as Array.

Return value

array PHP Info as Array.

See also

https://www.php.net/manual/de/function.phpinfo.php#106862

1 call to MetricService::getPhpInfoAsArray()
MetricService::getServerData in src/MetricService.php
Get Server Data.

File

src/MetricService.php, line 174

Class

MetricService
Class MetricService.

Namespace

Drupal\drupalmonitor

Code

public function getPhpInfoAsArray() {
  ob_start();
  phpinfo();
  $info_arr = [];
  $info_lines = explode("\n", strip_tags(ob_get_clean(), "<tr><td><h2>"));
  $cat = "General";
  foreach ($info_lines as $line) {

    // Check if a new category is shown on line.
    preg_match("~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : NULL;
    if (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
      $info_arr[$cat][$val[1]] = $val[2];
    }
    elseif (preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val)) {
      $info_arr[$cat][$val[1]] = [
        "local" => $val[2],
        "master" => $val[3],
      ];
    }
  }
  return $info_arr;
}