I had a lot of trouble with this, so I’m posting the solution for all to benefit. Thanks to this blog (http://blogs.msdn.com/b/john_pollard/archive/2007/03/07/performance-counters-fun.aspx) for the solution.
My test code is as follows:
$cmd = "typeperf \"\\\\".getenv("HTTP_HOST")."\\processor(_Total)\\% Processor Time\" -sc 1"; echo $cmd . "<br/>"; echo exec($cmd, $result=array()); print_r($result);
IIS is set up to use the IUSR_MACHINENAME (Internet Guest Account).
1. Set permission for IUSR to read and execute c:\windows\system32\cmd.exe (WARNING: THIS IS A SECURITY RISK! Do not do this on a production server)
2. Set permission for IUSR to read and execute c:\windows\system32\typeperf.exe
3. Set permission for IUSR to read the Perflib registry key located at “HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\Perflib”
Now, you should be able to read performance counters through your IIS web server. Note, there are probably better ways to handle step 1. If you know of a better method, please suggest one in the comments section and I’ll update this entry.
Hope this helps!