BrandonTheG
November 19th, 2007, 22:36
Hello,
I quickly developed this script today, not sure if it's good for anybody here, but if you ever want to know your CPU info, you can get it from here.
If you run `cat /proc/cpuinfo` you can see all this information, but this is perfect for showing this on your website, or seeing maybe what your host runs for hardware?
I can add more to this, but I need more resources to make this better. If anybody has a dual processor system, can you let me know the value for total CPU's (if any).
Thanks, and here is the script!
<?php
$proc_number = exec("grep 'model name' /proc/cpuinfo | wc -l");
for ($i = 0; $i < $proc_number; $i++) {
$model_name = exec("grep 'vendor_id' /proc/cpuinfo");
$model_name = explode(":", $model_name);
$model_name = trim($model_name[1]);
$model_vendor = exec("grep 'model name' /proc/cpuinfo");
$model_vendor = explode(":", $model_vendor);
$model_vendor = trim($model_vendor[1]);
$cpu_mhz = exec("grep 'cpu MHz' /proc/cpuinfo");
$cpu_mhz = explode(":", $cpu_mhz);
$cpu_mhz = trim($cpu_mhz[1]);
$cache_size = exec("grep 'cache size' /proc/cpuinfo");
$cache_size = explode(":", $cache_size);
$cache_size = trim($cache_size[1]);
// The following whill show cpu cores
// this is per proccessor so it will repeat.
if (exec("grep 'cpu cores' /proc/cpuinfo | wc -l") > 0) {
$cpu_cores = exec("grep 'core id' /proc/cpuinfo | wc -l");
$cpu_cores = trim($cpu_cores);
}else{
$cpu_cores = 1;
}
$cpuinfo[$i][model_vendor] = $model_name;
$cpuinfo[$i][model_name] = $model_vendor;
$cpuinfo[$i][cpu_mhz] = $cpu_mhz;
$cpuinfo[$i][cache_size] = $cache_size;
$cpuinfo[$i][cpu_cores] = $cpu_cores;
}
echo "<pre>";
print_r($cpuinfo);
echo "</pre>";
?>And here is a sample output from a quad-core system:
Array
(
[0] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
[1] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
[2] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
[3] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
)
If you have any feedback please feel free to ask.
I quickly developed this script today, not sure if it's good for anybody here, but if you ever want to know your CPU info, you can get it from here.
If you run `cat /proc/cpuinfo` you can see all this information, but this is perfect for showing this on your website, or seeing maybe what your host runs for hardware?
I can add more to this, but I need more resources to make this better. If anybody has a dual processor system, can you let me know the value for total CPU's (if any).
Thanks, and here is the script!
<?php
$proc_number = exec("grep 'model name' /proc/cpuinfo | wc -l");
for ($i = 0; $i < $proc_number; $i++) {
$model_name = exec("grep 'vendor_id' /proc/cpuinfo");
$model_name = explode(":", $model_name);
$model_name = trim($model_name[1]);
$model_vendor = exec("grep 'model name' /proc/cpuinfo");
$model_vendor = explode(":", $model_vendor);
$model_vendor = trim($model_vendor[1]);
$cpu_mhz = exec("grep 'cpu MHz' /proc/cpuinfo");
$cpu_mhz = explode(":", $cpu_mhz);
$cpu_mhz = trim($cpu_mhz[1]);
$cache_size = exec("grep 'cache size' /proc/cpuinfo");
$cache_size = explode(":", $cache_size);
$cache_size = trim($cache_size[1]);
// The following whill show cpu cores
// this is per proccessor so it will repeat.
if (exec("grep 'cpu cores' /proc/cpuinfo | wc -l") > 0) {
$cpu_cores = exec("grep 'core id' /proc/cpuinfo | wc -l");
$cpu_cores = trim($cpu_cores);
}else{
$cpu_cores = 1;
}
$cpuinfo[$i][model_vendor] = $model_name;
$cpuinfo[$i][model_name] = $model_vendor;
$cpuinfo[$i][cpu_mhz] = $cpu_mhz;
$cpuinfo[$i][cache_size] = $cache_size;
$cpuinfo[$i][cpu_cores] = $cpu_cores;
}
echo "<pre>";
print_r($cpuinfo);
echo "</pre>";
?>And here is a sample output from a quad-core system:
Array
(
[0] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
[1] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
[2] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
[3] => Array
(
[model_vendor] => GenuineIntel
[model_name] => Intel(R) Xeon(R) CPU X3220 @ 2.40GHz
[cpu_mhz] => 2394.663
[cache_size] => 4096 KB
[cpu_cores] => 4
)
)
If you have any feedback please feel free to ask.