public static function getCoreCount($recalculate = false)
{
static $processors = 0;
if ($processors > 0 and !$recalculate) {
return $processors;
} else {
$processors = 0;
}
switch (Utils::getOS()) {
case "linux":
case "android":
if (file_exists("/proc/cpuinfo")) {
foreach (file("/proc/cpuinfo") as $l) {
if (preg_match('/^processor[ \\t]*:[ \\t]*[0-9]+$/m', $l) > 0) {
++$processors;
}
}
} else {
if (preg_match("/^([0-9]+)\\-([0-9]+)\$/", trim(@file_get_contents("/sys/devices/system/cpu/present")), $matches) > 0) {
$processors = (int) ($matches[2] - $matches[1]);
}
}
break;
case "bsd":
case "mac":
$processors = (int) `sysctl -n hw.ncpu`;
$processors = (int) `sysctl -n hw.ncpu`;
break;
case "win":
$processors = (int) getenv("NUMBER_OF_PROCESSORS");
break;
}
return $processors;
}