I'm trying to use pthreads for multithreading. I'm creating pool with constructor. First parameter is number of Workers.
$pool = new Pool(8, 'WebWorker');
I want to detect count of processor cores automatically. Something like this:
$pool = new Pool(get_processor_cores_number(), 'WebWorker');
How is it possible with PHP?
If the server is a Linux machine you can do it with the following snippet:
$ncpu = 1;
if(is_file('/proc/cpuinfo')) {
$cpuinfo = file_get_contents('/proc/cpuinfo');
preg_match_all('/^processor/m', $cpuinfo, $matches);
$ncpu = count($matches[0]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With