Weave 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

Cpu Core Counter Laravel Package

fidry/cpu-core-counter

A tiny PHP utility for detecting CPU core counts, with logical and physical finders, built-in fallbacks, and memoized results. It also estimates cores available for parallel processes and lets you customize or reorder finders. Requires Composer.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Cpu Core Counter
How do I install fidry/cpu-core-counter in a Laravel application?
Install it with composer require fidry/cpu-core-counter. No Laravel service provider or framework configuration is required because it is a standalone PHP utility. You can instantiate CpuCoreCounter directly in a service, command, or config helper.
Does fidry/cpu-core-counter support Laravel 8+ and PHP 7.2+?
Yes. The package requires PHP 7.2+ and has no Laravel-specific dependencies, so it fits Laravel 8+ applications running supported PHP versions. It works across Linux, Windows, and macOS through its finder system. Laravel applications on newer PHP versions can use it without framework changes.
How can I use CPU core count to size Laravel queue workers?
Use getAvailableForParallelisation()->availableCpus when you need a parallelisation-friendly count, or getCountWithFallback() when a simple core count is enough. You can feed that value into queue worker configuration or deployment scripts. The package does not override Laravel queue scaling itself, so combine its output with your existing queue, Horizon, or container settings.
What happens when CPU core detection fails in production?
getCount() throws NumberOfCpuCoreNotFound when no finder can determine the core count. You can catch that exception and return a safe value, use getCountWithFallback(1), or append a DummyCpuCoreFinder with your fallback value. This makes it suitable for cloud VMs and restricted environments where detection may not always succeed.
Does fidry/cpu-core-counter detect CPU limits in Docker and Kubernetes?
The package added Kubernetes CPU limit support in version 1.3.0 and includes container-aware detection logic. Highly restricted Docker containers or non-standard cloud environments may still prevent detection, so validate in staging. Always provide a fallback such as getCountWithFallback(1) for production safety.
What is the difference between logical and physical CPU core detection?
Logical cores include hyperthreading and are the default because they usually match what PHP and parallel process launchers expect. Physical cores represent actual processor cores and can be selected through FinderRegistry::getDefaultPhysicalFinders(). Use logical cores for parallelisation and physical cores when you specifically need hardware-level counts.
Can I customize or disable specific CPU core finders?
Yes. Pass an ordered array of finder instances to CpuCoreCounter, or filter CpuCoreCounter::getDefaultFinders() to remove OS-specific finders such as WindowsWmicFinder. You can also reorder finders so CPUInfoFinder or another finder runs first. This lets you tune detection for your deployment environment.
Is the CPU core count result memoized and safe to call repeatedly?
Yes. CpuCoreCounter memoizes the result after detection, so repeated calls on the same instance avoid rerunning finders. Reuse the counter instance within a request or service rather than creating many new instances. Because the value is cached, environment changes during the same process lifetime will not be reflected.
How should I test Laravel code that depends on CPU core detection?
Inject CpuCoreCounter or a small wrapper service instead of calling detection directly in business logic. In tests, pass a DummyCpuCoreFinder with a known value such as 4, or bind a fake counter in Laravel's container. This avoids depending on the host machine's CPU configuration and keeps tests deterministic.
Is fidry/cpu-core-counter maintained and what alternatives should I consider?
It is a small, lightweight package with active maintenance history, including version 1.3.0, but low adoption may slow issue resolution. Monitor GitHub issues and keep a fallback value in production. For Linux-only deployments, native commands like nproc or reading /proc/cpuinfo can be alternatives, while this package is useful for cross-platform Laravel apps that want centralized finders and fallbacks.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo