Hi All, There is some serious issue with one of my servers. So, I thought of writing a small PHP script which gives me the CPU load just like the top command in linux environment? If any of you have done this, please provide me any pointers/directions. I would appreciate any help in this regard. Thanks in advance!! Best Regards, Inderpal Singh
I haven't tried this myself but this link seem to have what you are looking for forums.invisionpower.com/index.php?showtopic=156890 .
I would think php-sysinfo would be a good starting point. I think it is open source so maybe you can contribute some additional functionality
You might be able to open '/proc/loadavg' and read out the contents. Here's what my box reports: 0.04 0.02 0.00 1/92 7089 Code (markup): First three numbers will be average load over the last 1, 5 and 15 minutes. I have no idea what the next two are, though the last number looks like the current highest (or next) process id. You might also be interested in '/proc/meminfo'. Cryo.
Hi All, Thanks for all your help but I want the output exactly to be look like TOP command in linux. Best Regards, Inderpal Singh
only works on linux, dont forget to give me some of that green rep $uptime1 = @exec('uptime'); preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime1,$avgs1); $uptime1 = explode(' up ', $uptime1); $uptime1 = explode(',', $uptime1[1]); $uptime1 = $uptime1[0]; $start1=mktime(0, 0, 0, 1, 1, date("Y"), 0); $end1=mktime(0, 0, 0, date("m"), date("j"), date("y"), 0); $diff1=$end1-$start1; $days1=$diff1/86400; $percentage1=($uptime1/$days1) * 100; $load1=$avgs1[2]; PHP:
You all do things the complicated way <?php echo shell_exec('top -b -n 1'); ?> PHP: You may want to format it or just return it as regular text