Jump to content

[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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.