PDA

View Full Version : Monitor your server from PHP



a_bertrand
02-04-2009, 02:53 PM
A little script to get the HDD activity and memory / cpu usage. I used popen but you may use other functions as well.


<?PHP
echo "<PRE>\n";
echo "IO STATS\n";
$handle=popen("/usr/bin/iostat -k sda 1 2","r");
fread($handle,16000);
$lines=explode("\n",fread($handle,16000));
array_shift($lines);
array_shift($lines);
array_shift($lines);
echo implode("\n",$lines);
pclose($handle);

echo "Top\n";
$handle=popen("/usr/bin/top -b -n 1","r");
echo fread($handle,16000);
pclose($handle);
echo "</PRE>\n";
?>

Lithium
02-04-2009, 03:25 PM
Only *nix systems apply here though ;)

a_bertrand
02-04-2009, 04:39 PM
Honestly you would run your PHP scripts on a windows server? Would be a non-sense... I would run on a windows server only for ASPX applications (with IIS) but certainly not for a PHP installation. I do use PHP on windows but only for the development ;)

Why? Well simply check the memory usage of your server with just the OS loaded, and tell me which of a Linux box or a Windows box use less memory, add to that cron and ssh and you know why I use Linux as servers.

Jeff
02-04-2009, 07:19 PM
Nice little tip, thanks for sharing

Lithium
02-04-2009, 07:23 PM
a_bertrand: true enough, but then again there is still people that often use windows hosting instead ;)

Tonka
02-04-2009, 07:33 PM
Very nice a_bertrand

yuriorlov
02-04-2009, 11:41 PM
Honestly you would run your PHP scripts on a windows server? Would be a non-sense... I would run on a windows server only for ASPX applications (with IIS) but certainly not for a PHP installation. I do use PHP on windows but only for the development ;)

Why? Well simply check the memory usage of your server with just the OS loaded, and tell me which of a Linux box or a Windows box use less memory, add to that cron and ssh and you know why I use Linux as servers.


I'll give you a few reasons:
1.) GUI
2.) Compatibility with some nifty backend things you dont / cant get with unix / linux
3.) Memory is cheap 2gb DDR2 sticks are like $20

a_bertrand
02-05-2009, 12:37 AM
- Remote GUI is not good due to his slowness, unless you are in the same network.
- Compatibility with some back-ends, then yes, but I rarely saw a back-end which doesn't offer yet web services.
- Server memory is never cheap, specially if you need to rent your dedicated server.

Lithium
02-05-2009, 12:45 AM
Honestly you would run your PHP scripts on a windows server? Would be a non-sense... I would run on a windows server only for ASPX applications (with IIS) but certainly not for a PHP installation. I do use PHP on windows but only for the development ;)

Why? Well simply check the memory usage of your server with just the OS loaded, and tell me which of a Linux box or a Windows box use less memory, add to that cron and ssh and you know why I use Linux as servers.


I'll give you a few reasons:
1.) GUI
2.) Compatibility with some nifty backend things you dont / cant get with unix / linux
3.) Memory is cheap 2gb DDR2 sticks are like $20


GUI, let's see... windows windows windows... (for Windows) Xwindows, gnome, kde, and that tiny awesome fluxbox, among a few dozen more (for *nix).
Backend things you can't do with *nix flavours? name a couple...
Memory cheap... well as a_bertrand stated... Server memory is not cheap.