From 4f3b886799e3a5e0bd1bf3f0a047e11922c5b86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 4 Dec 2022 20:06:04 +0100 Subject: [PATCH] Update doc --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8debe9f..4872c06 100644 --- a/README.md +++ b/README.md @@ -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(); ```