Skip to content

Replace hand-rolled getCpuCores() with fidry/cpu-core-counter#80

Merged
voku merged 2 commits intomasterfrom
copilot/replace-get-cpu-cores
Apr 11, 2026
Merged

Replace hand-rolled getCpuCores() with fidry/cpu-core-counter#80
voku merged 2 commits intomasterfrom
copilot/replace-get-cpu-cores

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

The custom Utils::getCpuCores() reimplemented cross-platform CPU detection via shell_exec/wmic/nproc//proc/cpuinfo. Replace it with the battle-tested fidry/cpu-core-counter library.

Changes

  • composer.json: Add fidry/cpu-core-counter: ^1.3 to require
  • Utils::getCpuCores(): Replace ~50 lines of brittle shell detection with a delegation to CpuCoreCounter::getAvailableForParallelisation()->availableCpus; result is memoized via a static variable to avoid re-detection on repeated calls
  • Public method signature is unchanged — callers in PhpCodeParser are unaffected
public static function getCpuCores(): int
{
    static $cores = null;
    if ($cores === null) {
        $cores = (new \Fidry\CpuCoreCounter\CpuCoreCounter())->getAvailableForParallelisation()->availableCpus;
    }
    return $cores;
}

@sonarqubecloud
Copy link
Copy Markdown

@voku voku marked this pull request as ready for review April 11, 2026 04:11
@voku voku merged commit 3fcaa1a into master Apr 11, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants