Skip to content

Commit abc3fdb

Browse files
committed
Fall through if /sys/fs/cgroup/cpu/cpu.cfs_quota_us contains -1
1 parent bb138f6 commit abc3fdb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/php/lang/Runtime.class.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static function getInstance() {
3333
* @see https://stackoverflow.com/q/6481005 (Linux)
3434
* @see https://stackoverflow.com/q/1715580 (Mac OS)
3535
* @see https://stackoverflow.com/q/22919076 (Windows)
36+
* @see https://stackoverflow.com/a/49152519 (Docker w/ `--cpus=<n>`)
3637
* @see https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem
3738
* @return ?int|float
3839
*/
@@ -45,10 +46,13 @@ public function availableProcessors() {
4546
return $sys->NumberOfProcessors;
4647
}
4748
} else if (is_readable($f= '/sys/fs/cgroup/cpu/cpu.cfs_quota_us') && ($fd= fopen($f, 'r'))) {
48-
$n= fgets($fd, 1024);
49+
fscanf($fd, '%d', $n);
4950
fclose($fd);
50-
return (float)($n / 100000);
51-
} else if (is_readable($f= '/proc/cpuinfo') && ($fd= fopen($f, 'r'))) {
51+
if ($n > 0) return (float)($n / 100000);
52+
// Fall through
53+
}
54+
55+
if (is_readable($f= '/proc/cpuinfo') && ($fd= fopen($f, 'r'))) {
5256
$n= 0;
5357
do {
5458
$line= fgets($fd, 1024);

0 commit comments

Comments
 (0)