Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Adds support for Open Swoole v22.x #626

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}