3

I wrote this PHP function:

<?php
//windows cpu temperature
function win_cpu_temp(){
    $wmi = new COM("winmgmts://./root\WMI");
    $cpus = $wmi->execquery("SELECT * FROM MSAcpi_ThermalZoneTemperature");
    foreach ($cpus as $cpu) {
        $cpupre = $cpu->CurrentTemperature;
    }
    $cpu_temp = ($cpupre/10)-273.15 . ' C';
    return $cpu_temp;
}
echo win_cpu_temp();
?>

My problem, is that the script displays 59.55 C which I had thought was correct. I checked this value several hours later, and it's exactly the same. I just put the CPU to work at 90% compressing video for ten minutes, and this value is the same still.

Can anyone help me find the "true" value for this function?

I've read (to no avail): MSAcpi_ThermalZoneTemperature class not showing actual temperature

How is, say, "Core Temp" getting its values? Same computer, it reports between 49 and 53 Celsius.

1 Answer 1

5
+50

With a little digging around I found the common issue with using MSAcpi_ThermalZoneTemperature was that it is dependent upon being implemented on your system.

You could try querying Win32_TemperatureProbe and see if you have any luck there.

Neither MSAcpi_ThermalZoneTemperature or Win32_TemperatureProbe worked on my system, although if you have admin access, you can use http://openhardwaremonitor.org/ which provides a WMI interface for all available sensor data.

This worked great for me and I was able to accurately report CPU Core temp from a PHP script:

function report_cpu_temp(){    
    $wmi = new COM('winmgmts://./root/OpenHardwareMonitor');
    $result = $wmi->ExecQuery("SELECT * FROM Sensor");
    foreach($result as $obj){
        if($obj->SensorType == 'Temperature' && strpos($obj->Parent, 'cpu') > 0)
            echo "$obj->Name ($obj->Value C)"; // output cpu core temp
        else
            echo 'skipping ' . $obj->Identifier ;
        echo '<br />';
    }
}

Hope this helps.

2
  • This didn't work as-written on any of my systems, but I see where its going and will modify it accordingly.
    – ionFish
    Commented Apr 15, 2012 at 15:36
  • Works perfectly for me, just copy and paste code.. Ran perfectly.. Thanks, such as simple and good solution.
    – Yudhistre
    Commented Mar 15, 2021 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.