jrgp / linfo

Linfo PHP Server Health Status
MIT License
361 stars 73 forks source link

Cant get "cpuUsage" with "$linfo->getInfo();" #48

Closed noahwaldner closed 7 years ago

noahwaldner commented 7 years ago

Cant get the Value of "cpuUsage", its empty.

jrgp commented 7 years ago

You need to first call determineCPUPercentage() before running getInfo(). Something like the following should work:

$linfo = new \Linfo\Linfo;
$linfo->getParser()->determineCPUPercentage();
$linfo->getInfo();
noahwaldner commented 7 years ago

require_once dirname(FILE).'/init.php';

$linfo = new Linfo; $linfo->getParser()->determineCPUPercentage(); $linfo->scan(); $values = $linfo->getInfo();

in $values the CPU Usage Field is empty.

jrgp commented 7 years ago

Just looked into this. The following works for me:

<?php

require_once __DIR__ . '/standalone_autoload.php';

$linfo = new \Linfo\Linfo;
$parser = $linfo->getParser();
$parser->determineCPUPercentage();

var_dump($parser->getCPU());

And then:

$ php foo.php
array(4) {
  [0]=>
  array(4) {
    ["usage_percentage"]=>
    float(5)
    ["Vendor"]=>
    string(12) "GenuineIntel"
    ["Model"]=>
    string(39) "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz"
    ["MHz"]=>
    string(8) "3594.937"
  }

Admittedly the API could be cleaner but it works.