Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc #34

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,43 @@ composer require fidry/cpu-core-counter
use Fidry\CpuCounter\CpuCoreCounter;

$counter = new CpuCoreCounter();
$counter->getCount(); // e.g. 8

try {
$counter->getCount(); // e.g. 8
} catch (NumberOfCpuCoreNotFound) {
return 1; // Fallback value
}

```


## Advanced usage

### Changing the finders

When creating `CpuCoreCounter`, you may want to change the order of the finders
used or disable a specific finder. You can easily do so by passing the finders
you want

```php
// Remove WindowsWmicFinder
$finders = array_filter(
CpuCoreCounter::getDefaultFinders(),
static fn (CpuCoreFinder $finder) => !($finder instanceof WindowsWmicFinder)
);

$cores = (new CpuCoreCounter($finders))->getCount();
```

```php
// Use CPUInfo first & don't use Nproc
use Fidry\CpuCounter\CpuInfoFinder;use Fidry\CpuCounter\HwFinder;use Fidry\CpuCounter\WindowsWmicFinder;$finders = [
new CpuInfoFinder(),
new WindowsWmicFinder(),
new HwFinder(),
];

$cores = (new CpuCoreCounter($finders))->getCount();
```


Expand Down