diff --git a/src/Swoole/SwooleExtension.php b/src/Swoole/SwooleExtension.php index 4bc97f380..a795a4737 100644 --- a/src/Swoole/SwooleExtension.php +++ b/src/Swoole/SwooleExtension.php @@ -53,6 +53,14 @@ public function setProcessName(string $appName, string $processName): void */ public function cpuCount(): int { - return swoole_cpu_num(); + if (function_exists('swoole_cpu_num')) { + return swoole_cpu_num(); + } + + if (class_exists(\OpenSwoole\Util::class) && method_exists(\OpenSwoole\Util::class, 'getCPUNum')) { + return \OpenSwoole\Util::getCPUNum(); + } + + return 1; } } diff --git a/tests/SwooleExtensionTest.php b/tests/SwooleExtensionTest.php new file mode 100644 index 000000000..4e4d05a61 --- /dev/null +++ b/tests/SwooleExtensionTest.php @@ -0,0 +1,17 @@ +cpuCount(); + + $this->assertTrue($cpuCount > 0); + } +}