PHP Server info Script

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
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

PHP Server info Script

Post by dmallia »

So i want to do a basic admin page for my servers to display information.
The information that has to display is this:
Operating System Name
IP address
Uptime
CPU Information and CPU Load
Total Memory and memory being used
Total HDD Space and HDD Used Space

They both have linux OS(don't know if it makes any difference from windows)

Any idea on how to have that information?(till know i only know $_SERVER['SERVER_ADDR'] to get the ip adress)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Server info Script

Post by Celauran »

You will almost certainly need either exec() or system() which, on shared hosting, are unlikely to be enabled. I've listed the appropriate commands anyway.
  • Operating System Name: uname -o
  • Uptime: uptime
  • CPU Information and CPU Load: not sure
  • Total Memory and memory being used: free
  • Total HDD Space and HDD Used Space: df
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: PHP Server info Script

Post by dmallia »

To display the cpu usage load i found this ajax script http://www.obout.com/AJAXPage/ex_cpumon.aspx but i don't know how i can insert it in my php page. Anyone knows how i can add this script?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Server info Script

Post by Celauran »

It appears to be written in C#, so I expect that will pose some problems.
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: PHP Server info Script

Post by dmallia »

hope i will fine another one that will work, as i don't know how to program in ajax
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: PHP Server info Script

Post by dmallia »

So for the cpu information i did this script.

Code: Select all

<?php

	$cpuinfo = file("/proc/cpuinfo");

	for ($i = 0; $i < count($cpuinfo); $i++)
		{
			list($item, $data) = split(":", $cpuinfo[$i], 2);
			$item = chop($item);
			$data = chop($data);
			if ($item == "processor") {$total_cpu++; }
			if ($item == "vendor_id") { $vendor_id = $data; }
			if ($item == "model name") { $cpu_name = $data; }
			if ($item == "cpu MHz") {$cpu_speed = " " . floor($data);}
		}

	$cpu_info = $total_cpu.'x '.$vendor_id.' '.$cpu_name.' '.$cpu_speed." MHz\n";

	$cpu = "<p>CPU :".$cpu_info."</p>";

	echo $cpu;
?>
but i'm getting these errors with the cpu information. Anyone can tell me how i can remove these errors?

Code: Select all

Notice: Undefined variable: total_cpu in /var/www/html/daniel/index.php on line 10 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7

CPU :4x GenuineIntel Intel(R) Xeon(R) CPU X3360 @ 2.83GHz 2825 MHz
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: PHP Server info Script

Post by dmallia »

Problem solved. Just made another script and instead of a loop i made the loop my self.
Post Reply