PHP Salt


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

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
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:

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