Web Hosting Talk







View Full Version : Get Load Average, Ping, CPU load, etc. by using PHP


Milos
03-03-2002, 08:43 PM
Hi all !
in earlier discussions were some tips for service status checking by using port (e.g. 80 for http, etc.).

Is there any chance get following features also with PHP?

- Ping (test if remote server answer, and if yes, how ms it takes (ms are not needed if it is not so easy :)
- Number of Opened Files
- Current % of maximal opened files
- Server average load
- CPU load
- Free MEM

THANK YOU VERY MUCH FOR YOUR TIPS!

Btw, I solve previous features by using following PHP code, but it works at local machine only, and I need to work it out on remote machines also.

<?
$filesa=fopen("/proc/loadavg","r");
//@fpassthru($filesa);
$fline = fgets($filesa,100);
fclose($filesa);
List($onem,$fivem,$tenm,$trash1,$trah2) = Explode(" ",$fline);
$filesa=fopen("/proc/sys/fs/file-nr","r");
//@fpassthru($filesa);
$fline = fgets($filesa,100);
$datime = Date("d.m.Y H:i:s");
List(,$cur,$max) = explode(Chr(9),$fline);
$procs=Round($cur/($max/100),2);

echo("$cur files opened ($procs %) with <B>$onem</B> load");

@fclose($filesa);
?>

goodness0001
03-03-2002, 10:27 PM
Using this code in php will reveal the load, memory, uptime, PHP safe mode must be off.

echo shell_exec(uptime);

goodness0001
03-03-2002, 10:36 PM
I posted my solution which is built off of a script that was developed by another user, and also combined an idea from scripts.tlcwe.com

http://www.webhostingtalk.com/showthread.php?s=&postid=272972#post272972