Get server details with php ...

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
fishown
Forum Commoner
Posts: 33
Joined: Sat May 12, 2007 5:35 pm

Get server details with php ...

Post by fishown »

Just a thught, Ther is any way to get server (running linux) infromation?
What I have in mind is like:

how many and which partations are out ther?
What is the hardware that the server is running?
How much precent of the CPU/MEMORY is beeing used at the moment the script is running?

Thanka s lot,
Ill keep search Google as well.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Get server details with php ...

Post by social_experiment »

No idea on the CPU information etc but you can use the $_SERVER array to get information about the server.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
fishown
Forum Commoner
Posts: 33
Joined: Sat May 12, 2007 5:35 pm

Re: Get server details with php ...

Post by fishown »

thanks , but iv'e kinda find that alredy...

I have one more question,

Ther is any way to find out which Drives ther are in the server?
Like hard drive / partations some thing like this.

because i have a function that check the space on my server, but i want the function
to self update if ill add more hard drives to the server, like i wont need to change the code.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Get server details with php ...

Post by McInfo »

That type of information can be found in files under /proc.

To see what files are available, use dir or ls at the command prompt.

Code: Select all

ls /proc
To see what is in a file, use cat.

Code: Select all

cat /proc/partitions
You will have to do a little research to learn where in those files to find the information you are looking for.

In PHP, you can run system commands with program execution functions.

Some commands like fdisk give access to system information, but may require root permission; and it is atypical for PHP to be run by root.
fishown
Forum Commoner
Posts: 33
Joined: Sat May 12, 2007 5:35 pm

Re: Get server details with php ...

Post by fishown »

First of all, THANK YOU.
Im steping forword...
so i built this little function

Code: Select all

<?php 
$stats = shell_exec('cat /proc/partitions'); 
if($stats){ 
echo "success<br>".$stats; 

} else
	echo "unsuccessful"; 
?> 
and the output that I recived is :
major minor #blocks name 8 0 20971520 sda 8 1 104391 sda1 8 2 2096482 sda2 8 3 18763920 sda3 7 0 512000 loop0
Now, i wonder if you have any idea how to work with this output...

thanks,
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Get server details with php ...

Post by McInfo »

If you display the script output as plain text instead of HTML, you will see that the text is actually a table with fixed-width columns.

Code: Select all

major minor  #blocks  name

   8        0   20971520 sda
   8        1     104391 sda1
   8        2    2096482 sda2
   8        3   18763920 sda3
   7        0     512000 loop0
If you split (explode) the string on the newlines (the "\n" character), you will have an array of lines. Ignoring the first two lines (the column headers and the blank line), each element of the array is a row of the table. Further, you can split each row into an array of cells, yielding a two-dimensional array. There are many ways to accomplish that using PHP's string and array functions.
fishown
Forum Commoner
Posts: 33
Joined: Sat May 12, 2007 5:35 pm

Re: Get server details with php ...

Post by fishown »

First thing thanks,

Let me know if i got it right ,

The partations are sda...sda1..sda2 right?
If so I got it ...

One Last thing... what about hard drives ? Do you have any idea where i see that?
thank you =]
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: Get server details with php ...

Post by jarofgreen »

Look at this thread
viewtopic.php?f=50&t=123299
fishown
Forum Commoner
Posts: 33
Joined: Sat May 12, 2007 5:35 pm

Re: Get server details with php ...

Post by fishown »

jarofgreen wrote:Look at this thread
viewtopic.php?f=50&t=123299
Thank you, and every one that posted on the thred!

I just wanted to say that I kinda wanted to do it myself,
But that will work just fine.

Thank you agian.
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: Get server details with php ...

Post by jarofgreen »

It's open source, I'm sure they would welcome contributors :-)
Post Reply