Getting Current CPU Usage

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

Post Reply
Tommaso
Forum Newbie
Posts: 5
Joined: Sat Sep 02, 2006 2:07 am

Getting Current CPU Usage

Post by Tommaso »

I am having some trouble using PHP to get the current CPU usage of my computer. This is what i have tried so far, but $Output never fills

Attempt 1 (Using linux command top)

Code: Select all

exec('top -i -n 1', $Output);
echo 'Process Output:';
foreach($Output as $Key => $Value)
{
echo $Key;
}
Attempt 2 (Using linux command ps)

Code: Select all

exec('ps -ax', $Output);
echo 'Process Output:';
foreach($Output as $Key => $Value)
{
echo $Key;
}
Any help or suggestions would be appreciated.
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

Perhaps you should try echoing $Value instead ;)
Tommaso
Forum Newbie
Posts: 5
Joined: Sat Sep 02, 2006 2:07 am

Post by Tommaso »

I think i am going to bang my head agains the screen for 5 minutes now....Thanks for the help :)
Post Reply