Skip to content

Commit 5836d87

Browse files
committed
Determine number of cores on macOS
1 parent 2392fd8 commit 5836d87

File tree

1 file changed

+17
-0
lines changed
  • src/voku/SimplePhpParser/Parsers/Helper

1 file changed

+17
-0
lines changed

src/voku/SimplePhpParser/Parsers/Helper/Utils.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,23 @@ public static function getCpuCores(): int
495495
}
496496
}
497497

498+
/**
499+
* macOS (FreeBSD)
500+
*/
501+
$ret = @\shell_exec('sysctl -n hw.ncpu');
502+
if (\is_string($ret)) {
503+
$ret = \trim($ret);
504+
/** @noinspection PhpAssignmentInConditionInspection */
505+
if ($ret && ($tmp = \filter_var($ret, \FILTER_VALIDATE_INT)) !== false) {
506+
$return = (int)round($tmp / 2);
507+
if ($return > 1) {
508+
return $return;
509+
}
510+
511+
return 1;
512+
}
513+
}
514+
498515
return 1;
499516
}
500517

0 commit comments

Comments
 (0)