Skip to content

Commit

Permalink
Merge pull request #626 from laravel/patch-1
Browse files Browse the repository at this point in the history
[1.x] Adds support for Open Swoole `v22.x`
  • Loading branch information
nunomaduro authored Dec 23, 2022
2 parents bcd6ffe + fc2c445 commit 35243aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Swoole/SwooleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
17 changes: 17 additions & 0 deletions tests/SwooleExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Laravel\Octane\Tests;

use Laravel\Octane\Swoole\SwooleExtension;

class SwooleExtensionTest extends TestCase
{
public function test_cpu_count()
{
$extension = new SwooleExtension();

$cpuCount = $extension->cpuCount();

$this->assertTrue($cpuCount > 0);
}
}

0 comments on commit 35243aa

Please sign in to comment.