1. Go to this page and download the library: Download fidry/cpu-core-counter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fidry / cpu-core-counter example snippets
use Fidry\CpuCoreCounter\CpuCoreCounter;
use Fidry\CpuCoreCounter\NumberOfCpuCoreNotFound;
use Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder;
$counter = new CpuCoreCounter();
// For knowing the number of cores you can use for launching parallel processes:
$counter->getAvailableForParallelisation()->availableCpus;
// Get the number of CPU cores (by default it will use the logical cores count).
// This count does not account for CPU quotas or limits, e.g. `docker run --cpus=2`
// or KUBERNETES_CPU_LIMIT. Use ::getAvailableForParallelisation() to account for them.
try {
$counter->getCount(); // e.g. 8
} catch (NumberOfCpuCoreNotFound) {
return 1; // Fallback value
}
// Alternatively, to avoid having to catch the exception:
$counter = new CpuCoreCounter([
...CpuCoreCounter::getDefaultFinders(),
new DummyCpuCoreFinder(1), // Fallback value
]);
// A type-safe alternative form:
$counter->getCountWithFallback(1);
// Note that the result is memoized.
$counter->getCount(); // e.g. 8
// Use CPUInfo first & don't use Nproc
$finders = [
new CpuInfoFinder(),
new WindowsWmicFinder(),
new HwLogicalFinder(),
];
$cores = (new CpuCoreCounter($finders))->getCount();
$result = $counter->getAvailableForParallelisation();
$result->totalCoresCount; // e.g. 8
$result->correctedCountLimit; // e.g. 2, or null if there is no limit
$result->availableCpus; // e.g. 2
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.