Page 1 of 1
Get server details with php ...
Posted: Fri Jan 07, 2011 8:50 am
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.
Re: Get server details with php ...
Posted: Fri Jan 07, 2011 11:17 am
by social_experiment
No idea on the CPU information etc but you can use the $_SERVER array to get information about the server.
Re: Get server details with php ...
Posted: Fri Jan 07, 2011 1:26 pm
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.
Re: Get server details with php ...
Posted: Fri Jan 07, 2011 2:59 pm
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.
To see what is in a file, use
cat.
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.
Re: Get server details with php ...
Posted: Fri Jan 07, 2011 8:01 pm
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,
Re: Get server details with php ...
Posted: Fri Jan 07, 2011 11:53 pm
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.
Re: Get server details with php ...
Posted: Sat Jan 08, 2011 3:04 pm
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 =]
Re: Get server details with php ...
Posted: Sun Jan 09, 2011 10:40 am
by jarofgreen
Re: Get server details with php ...
Posted: Sun Jan 09, 2011 12:00 pm
by fishown
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.
Re: Get server details with php ...
Posted: Sun Jan 09, 2011 12:33 pm
by jarofgreen
It's open source, I'm sure they would welcome contributors
