PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
madhuj1260
Forum Newbie
Posts: 5 Joined: Wed Jun 10, 2009 3:26 am
Post
by madhuj1260 » Wed Jun 10, 2009 3:30 am
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.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jun 10, 2009 11:22 am
You can execute shell commands with PHP. Maybe investigate that.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
madhuj1260
Forum Newbie
Posts: 5 Joined: Wed Jun 10, 2009 3:26 am
Post
by madhuj1260 » Thu Jun 11, 2009 12:34 am
sorry, I havent informed u one thing I want this for windows system
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Jun 11, 2009 9:46 am
Oh, then I don't know.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mikemike
Forum Contributor
Posts: 355 Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK
Post
by mikemike » Thu Jun 11, 2009 10:02 am
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();
}
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Thu Jun 11, 2009 9:19 pm
Related topic:
Average CPU load on Windows?
Edit: This post was recovered from search engine cache.
Last edited by
McInfo on Tue Jun 15, 2010 10:55 pm, edited 1 time in total.
madhuj1260
Forum Newbie
Posts: 5 Joined: Wed Jun 10, 2009 3:26 am
Post
by madhuj1260 » Sat Jun 13, 2009 11:10 am
As I am beginner in php can u tell me how can I link up this c program to my php web page
mikemike
Forum Contributor
Posts: 355 Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK
Post
by mikemike » Sat Jun 13, 2009 11:14 am
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Sat Jun 13, 2009 2:27 pm
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.
Last edited by
McInfo on Tue Jun 15, 2010 10:56 pm, edited 1 time in total.
madhuj1260
Forum Newbie
Posts: 5 Joined: Wed Jun 10, 2009 3:26 am
Post
by madhuj1260 » Sun Jun 14, 2009 12:39 am
I tried this but this cannot be used for maintaining the values in the variable as this is of a command line application.