PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.13.2
Last Build: October 09, 2016 21:15pm (PST)

psInfoCPU()
CPU Info


Description:

Returns CPU Info


Usage:

psInfoCPU(STRING);


Example:


$ary = psInfoCPU();
print_r($ary);




Code:


function psInfoCPU()
{
static $res;

if ( !isset($res) )
{

$res['logical'] = 1;
if (is_file('/proc/cpuinfo'))
{
$cpuinfo = file_get_contents('/proc/cpuinfo');
preg_match_all('/^processor/m', $cpuinfo, $matches);
$numCpus = count($matches[0]);
$res['logical'] = $numCpus;
}

// kinda dirty, need to clean and make better
$cmd = "cat /proc/cpuinfo | grep 'model name' | uniq | cut -f2 -d':'";
$out =trim(`$cmd`);
list($res['name'],$res['speed']) = explode("@",$out);

// kinda dirty, need to clean and make better
$cmd = "cat /proc/cpuinfo | grep 'cpu cores' | uniq | cut -f2 -d':'";
$out =trim(`$cmd`);
$res['cores'] = $out;
$res['cpu'] = $res['logical'] / $res['cores'];
}




return $res;
}



Changlelog:

Based on code from: Erin Millard, https://gist.github.com/ezzatron/1321581
Static Cache idea from: Dumitru Uzun, https://gist.github.com/duzun


See Also

And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site