1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/linuxdash_ynh.git synced 2024-09-03 19:36:07 +02:00
linuxdash_ynh/sources/sh/numberofcores.php
2014-06-02 13:38:03 +02:00

31 lines
632 B
PHP

<?php
$intOpts = array(
'options' => array(
'min_range' => 1,
),
);
// get value via /proc/cpuinfo
$numOfCores = shell_exec('LC_ALL=C /bin/grep -c ^processor /proc/cpuinfo');
$numOfCores = filter_var(
$numOfCores[0],
FILTER_VALIDATE_INT,
$intOpts
);
// If number of cores is not found, run fallback
if ($numOfCores === false) {
$numOfCores = filter_var(
shell_exec('/usr/bin/nproc'),
FILTER_VALIDATE_INT,
$intOpts
);
}
if ($numOfCores === false) {
$numOfCores = 'unknown';
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($numOfCores);