如何在Windows上以PHP的形式获取每个CPU Core的负载?

Is there a way to do so? I tried using WMI, and the Win32_PerfRawData_PerfOS_Processor class, i end up having the PercentProcessorTime and Timestamp_PerfTime which would require to sleep a while to calculate the percentage, but thats not what i need, i need something that does not require PHP to wait a couple second, it should print out the load almost instantly

One way would be to have another program that continuously checks and logs the processor load somewhere where PHP would be able to read the values directly. There would probably be a slight delay in the logging but nothing like a couple of seconds.

You could probably do that in a separate PHP script. Just make sure you sleep() for a short while between the checks, otherwise the processor reading script would push the processor to maximum load immediately.

You could use XPerf, log the CPU activity and then access those log files via PHP? There also other suggestions in threads such as this one, which suggest giving Linfo a try.

I Know This Is A Old Post But I Was In The Same Position A While Back But Managed To Figure It Out.

Instead Of Using

Win32_PerfRawData_PerfOS_Processor

Use

Win32_PerfFormattedData_PerfOS_Processor

For Example

$data['core']  = array();
$wmi           = new COM("winmgmts:\\");
$cpu_cores     = $wmi->execquery("SELECT PercentProcessorTime FROM Win32_PerfFormattedData_PerfOS_Processor");

foreach ($cpu_cores as $core) {
    $data['core'][] = $core->PercentProcessorTime;
}

// If CPU Is A Dual Core 
echo $data['core'][0].'%'; // CORE 1 LOAD
echo $data['core'][1].'%'; // CORE 2 LOAD
echo $data['core'][2].'%'; // TOTAL CPU LOAD

// If CPU Is A Quad Core 
echo $data['core'][0].'%'; // CORE 1 LOAD
echo $data['core'][1].'%'; // CORE 2 LOAD
echo $data['core'][2].'%'; // CORE 3 LOAD
echo $data['core'][3].'%'; // CORE 4 LOAD
echo $data['core'][4].'%'; // TOTAL CPU LOAD

And So On