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().
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.
CpuCoreCounter::getDefaultFinders() (e.g., exclude WindowsWmicFinder if causing issues) or prepending environment-specific finders like CpuInfoFinder.KUBERNETES_CPU_LIMIT (millicores) to cap CPU count based on container quotas instead of host cores.CpuCoreCounter once (e.g., via DI container) since all methods memoize results internally—avoid repeated instantiation in hot code paths.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.ParallelisationResult values.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).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).WindowsWmicFinder or HwLogicalFinder only if wmic cpu get NumberOfCores isn’t available; fallback to DummyCpuCoreFinder only when diagnosis confirms no working finder exists.How can I help you explore Laravel packages today?