PHPackages                             wyrihaximus/cpu-core-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wyrihaximus/cpu-core-detector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wyrihaximus/cpu-core-detector
=============================

Detect how many CPU cores are available

2.0.0(5y ago)8276.9k↓47.3%1[4 PRs](https://github.com/WyriHaximus/php-cpu-core-detector/pulls)1MITPHPPHP ^7.4 || ^8

Since Jan 29Pushed 1w ago2 watchersCompare

[ Source](https://github.com/WyriHaximus/php-cpu-core-detector)[ Packagist](https://packagist.org/packages/wyrihaximus/cpu-core-detector)[ GitHub Sponsors](https://github.com/WyriHaximus)[ RSS](/packages/wyrihaximus-cpu-core-detector/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (8)Versions (11)Used By (1)

PHP CPU Core Count Detection
============================

[](#php-cpu-core-count-detection)

This PHP script detects the number of CPU cores available on a Linux server. It can be helpful for optimizing performance in multi-threaded applications by dynamically assessing hardware capabilities.

Purpose
-------

[](#purpose)

This tool enables developers to retrieve the number of CPU cores on a Linux server using PHP. This is especially useful for performance optimizations and load balancing in server environments.

Features
--------

[](#features)

- Detects the number of CPU cores on Linux-based systems.
- Utilizes shell commands (`hash`, `nproc`, `taskset`) to gather system information.
- Lightweight and easy to integrate into existing PHP applications.

Supported OS/Programs
---------------------

[](#supported-osprograms)

Currently supports **Linux** only, using the following utilities:

- `hash`
- `nproc`
- `taskset`

Clone this repository:
----------------------

[](#clone-this-repository)

```
git clone https://github.com/your-user/php-cpu-core-detection.git
```

Contributing
------------

[](#contributing)

Contributions are welcome! To contribute:

1. Fork this repository.
2. Make your changes in a new branch.
3. Submit a pull request with a detailed description of your changes.

Examples
--------

[](#examples)

Check out these examples to see the CPU core detection in action:

### Async

[](#async)

```
$loop = Factory::create();

Detector::detectAsync($loop)->then(function ($result): void {
   echo $result, \PHP_EOL;
   for ($i = 0; $i < $result; $i++) {
       Resolver::resolve($i, 'uptime')->then(function ($cmd): void {
           echo $cmd, \PHP_EOL;
       });
   }
});

$loop->run();

```

[Full Example](examples/async.php)

### Sync

[](#sync)

```
$result = Detector::detect();
echo $result, \PHP_EOL;

for ($i = 0; $i < $result; $i++) {
   Resolver::resolve((string)$i, 'uptime')->then(function ($cmd): void {
       echo $cmd, \PHP_EOL;
   });
}

```

[Full Example](examples/sync.php)

License
-------

[](#license)

Copyright 2016 [Cees-Jan Kiewiet](http://wyrihaximus.net/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance64

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 63.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~373 days

Recently: every ~455 days

Total

6

Last Release

1945d ago

Major Versions

1.0.x-dev → 2.0.02021-03-08

PHP version history (2 changes)1.0.0-alpha1PHP ^5.4||^7.0

2.0.0PHP ^7.4 || ^8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

---

Top Contributors

[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (112 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (45 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (18 commits)")[![Anuraj-IND](https://avatars.githubusercontent.com/u/140227135?v=4)](https://github.com/Anuraj-IND "Anuraj-IND (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

cpuhacktoberfestphpreactphp

### Embed Badge

![Health badge](/badges/wyrihaximus-cpu-core-detector/health.svg)

```
[![Health](https://phpackages.com/badges/wyrihaximus-cpu-core-detector/health.svg)](https://phpackages.com/packages/wyrihaximus-cpu-core-detector)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.3k](/packages/friendsofphp-php-cs-fixer)[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[react/react

ReactPHP: Event-driven, non-blocking I/O with PHP.

9.1k3.7M65](/packages/react-react)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
