Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

[SOLVED] CPU % (NON LINUX)


Recommended Posts

Even though this is not QUITE related to a webserver, some webservers return the usage% in a sys variable but mine doesnt. 

 

How would I get the cpu usage from the commandline or in my php script?

 

 

 

like I could say:

 

if ($CPUSG > 75) {
error_msg('The server is busy processing user's requests.  Please try again later.',500);
}

 

But how would I get the cpu usage?

Link to comment
https://forums.phpfreaks.com/topic/72271-solved-cpu-non-linux/
Share on other sites

when you say "non linux" I am assuming that you mean windows, correct? If so you can use wmi with COM. Like this..

 

<?php
$wmi = new COM('winmgmts://');
$processor = $wmi->ExecQuery("SELECT * FROM Win32_Processor");
foreach($processor as $obj){
$cpu_load = $obj->LoadPercentage;
}
if($cpu_load > 75) {
//do something
}
?>

 

For more info see http://msdn2.microsoft.com/en-us/library/aa394373.aspx

 

Link to comment
https://forums.phpfreaks.com/topic/72271-solved-cpu-non-linux/#findComment-364600
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.