Page 1 of 1
Retrieving CPU load using PHP classes for web applications
Posted: Wed Jun 10, 2009 3:30 am
by madhuj1260
hi all,
I am writing an application which needs to retrieve the CPU load of the server a particular instant of time. can nyone plz help me. plz note that this is for a web application.
Thanks in advance.

Re: Retrieving CPU load using PHP classes for web applications
Posted: Wed Jun 10, 2009 11:22 am
by pickle
You can execute shell commands with PHP. Maybe investigate that.
Re: Retrieving CPU load using PHP classes for web applications
Posted: Thu Jun 11, 2009 12:34 am
by madhuj1260
sorry, I havent informed u one thing I want this for windows system
Re: Retrieving CPU load using PHP classes for web applications
Posted: Thu Jun 11, 2009 9:46 am
by pickle
Oh, then I don't know.
Re: Retrieving CPU load using PHP classes for web applications
Posted: Thu Jun 11, 2009 10:02 am
by mikemike
There is no command for checkig CPU usage on Windows I don't think. You can write a simple C program though and just call that using system().
Code: Select all
# include <stdio.h>
# include <pdh.h>
double cpuLoad[10];
double avgCpuLoad = 0;
int i;
void DispTime()
{
HQUERY hQuery;
HCOUNTER hCounter;
PDH_FMT_COUNTERVALUE FmtValue;
PdhOpenQuery(NULL, 0, &hQuery);
PdhAddCounter(hQuery, "\\Processor(_Total)\\% Processor Time", 0, &hCounter);
printf("Starting the process...\n");
PdhCollectQueryData(hQuery);
PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, &FmtValue);
printf("The cpu usage is : %f%%\n", FmtValue.doubleValue);
PdhCloseQuery(hQuery);
}
void main()
{
DispTime();
getchar();
}
Re: Retrieving CPU load using PHP classes for web applicatio
Posted: Thu Jun 11, 2009 9:19 pm
by McInfo
Related topic:
Average CPU load on Windows?
Edit: This post was recovered from search engine cache.
Re: Retrieving CPU load using PHP classes for web applications
Posted: Sat Jun 13, 2009 11:10 am
by madhuj1260
As I am beginner in php can u tell me how can I link up this c program to my php web page

Re: Retrieving CPU load using PHP classes for web applications
Posted: Sat Jun 13, 2009 11:14 am
by mikemike
Re: Retrieving CPU load using PHP classes for web applicatio
Posted: Sat Jun 13, 2009 2:27 pm
by McInfo
The C code needs to be compiled into an executable (.exe) first. I would compile it, but I don't know where to download a compatible pdh.h helper file.
It would probably be easier to use this PHP code that I posted in
the thread that I linked to before.
Code: Select all
<?php
header('Content-Type: text/plain');
echo system('typeperf "\Processor(*)\% Processor Time"');
?>
Edit: This post was recovered from search engine cache.
Re: Retrieving CPU load using PHP classes for web applications
Posted: Sun Jun 14, 2009 12:39 am
by madhuj1260
I tried this but this cannot be used for maintaining the values in the variable as this is of a command line application.