Getting CPU usage information in PHP
Moderator: General Moderators
Getting CPU usage information in PHP
I am looking for a way to get process specfic CPU usage information. I took a look at win32ps.dll, and the function win32_ps_stat_proc... but all that has is CPU Time, I need the actual CPU usage at the time that the query takes place.
Any ideas? Any help would be appreciated.
Any ideas? Any help would be appreciated.
use the formulaes from http://www.alexfedotov.com/samples/wmitop.asp
well, you can't force PHP to wait for exact time period, but you can get the period of time elapsed between two invocations of microtime() function.
Is resolution down to microsecond enough for your task?
Is resolution down to microsecond enough for your task?
I have no idea about PHP's behind the scenes mechanisms but I guess functions aren't initialised unless they are going to be used. The following code shows what I'm saying to be fact:nickvd wrote:why would that be?
Code: Select all
<?php
function elapsed_time_in_microseconds($start, $end){
$start = explode(' ', $start);
$start = $start[0] + $start[1];
$end = explode(' ', $end);
$end = $end[0] + $end[1];
return (round(($end - $start) * 1000000));
}
$first = microtime();
$second = microtime();
$third = microtime();
$forth = microtime();
$fifth = microtime();
print(elapsed_time_in_microseconds($first, $second) . ' microseconds<br>'); // 36 microseconds
print(elapsed_time_in_microseconds($second, $third) . ' microseconds<br>'); // 9 microseconds
print(elapsed_time_in_microseconds($third, $forth) . ' microseconds<br>'); // 10 microseconds
print(elapsed_time_in_microseconds($forth, $fifth) . ' microseconds<br>'); // 9 microseconds
?>Also you need to understand you are only timing runtime. Compile time of course is not included.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US