Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cpu Core Counter Laravel Package

fidry/cpu-core-counter

Tiny PHP utility to detect CPU core count (logical or physical) with memoized results. Provides sensible defaults plus configurable “finders” per OS, parallelisation-friendly available cores, and safe fallbacks via exception handling or getCountWithFallback().

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package with composer require fidry/cpu-core-counter. Start by using the simplest integration: new CpuCoreCounter()->getCountWithFallback(1) to safely get the core count without exception handling. For parallel workload sizing, prefer $counter->getAvailableForParallelisation()->availableCpus. Run the included diagnose script (./vendor/fidry/cpu-core-counter/bin/diagnose.php) on your deployment targets to understand which finders succeed/fail in your environment before writing custom logic.

Implementation Patterns

  • Smart fallback chains: Override default finders by filtering CpuCoreCounter::getDefaultFinders() (e.g., exclude WindowsWmicFinder if causing issues) or prepending environment-specific finders like CpuInfoFinder.
  • Kubernetes-aware sizing: Leverage the 1.3.0+ support for KUBERNETES_CPU_LIMIT (millicores) to cap CPU count based on container quotas instead of host cores.
  • Memoized singleton pattern: Instantiate CpuCoreCounter once (e.g., via DI container) since all methods memoize results internally—avoid repeated instantiation in hot code paths.
  • Parallel worker provisioning: Use getAvailableForParallelisation() to configure thread pools in CLI tools or web workers (e.g., Guzzleconcurrency, Amp workers), adjusting cpus_for_parallelisation based on host vs container context.

Gotchas and Tips

  • Environment detection quirks: In containers or constrained environments (e.g., Docker, Kubernetes), logical CPU counts may reflect host cores, not quotas—always verify with the diagnose script or inspect ParallelisationResult values.
  • BCP exclusions: Avoid relying on internals like FinderRegistry::getDefaultFinders() order or private methods (@internal), as they’re excluded from the backward compatibility promise (especially after 1.2.0 changes to finder resolution).
  • Debugging strategy: When getCount() returns unexpected values, use trace() to log the finder chain resolution, and compare against getAvailableForParallelisation() output to see how parallel-friendly CPU count is derived (e.g., considering hyperthreading, reserved cores).
  • Windows-specific traps: Prefer WindowsWmicFinder or HwLogicalFinder only if wmic cpu get NumberOfCores isn’t available; fallback to DummyCpuCoreFinder only when diagnosis confirms no working finder exists.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport