File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ public static function getInstance() {
33
33
* @see https://stackoverflow.com/q/6481005 (Linux)
34
34
* @see https://stackoverflow.com/q/1715580 (Mac OS)
35
35
* @see https://stackoverflow.com/q/22919076 (Windows)
36
+ * @see https://stackoverflow.com/a/49152519 (Docker w/ `--cpus=<n>`)
36
37
* @see https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem
37
38
* @return ?int|float
38
39
*/
@@ -45,10 +46,13 @@ public function availableProcessors() {
45
46
return $ sys ->NumberOfProcessors ;
46
47
}
47
48
} 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 );
49
50
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 ' ))) {
52
56
$ n = 0 ;
53
57
do {
54
58
$ line = fgets ($ fd , 1024 );
You can’t perform that action at this time.
0 commit comments