Home arrow PHP arrow Page 8 - Retrieving System Information With patSysinfo

Mounting Up - PHP

Linux file structure contains within it a special area called /proc. Now, some believe that there's black magic in that directory. For those who know better than to fear the /proc, there awaits much good magic, in the form of server info. Looking for a way to retrieve real-time server information and display it to users in your Web application? Today's your lucky day! Take a look at the patSysinfo PHP class, which lets you do that and a whole lot more.

  1. Retrieving System Information With patSysinfo
  2. Plug and Play
  3. What's in a Name?
  4. Up and at 'Em
  5. Carrying the Load
  6. A Nifty Device
  7. Running Out of RAM
  8. Mounting Up
  9. Link Zone
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 19
February 16, 2004

print this article



Finally, you can obtain information on mounted file system with the getMounts() method, which returns an array containing detailed information from both the "df" command and "/proc/mounts". Take a look:

// include class
// instantiate object
$sys = new patSysinfo(); 
// get mounted file systems
$mounts = $sys->getMount(); 
// output mount information
print_r($mounts); die;
? >

Here's what the output of this script might look like:

    [0] => Array
            [disk] => /dev/hda3
            [size] => 4.73 GByte
            [used] => 923.00 MByte
            [free] => 3.59 GByte
            [percent] => 21
            [mount] => /
            [type] => ext2

    [1] => Array
            [disk] => /dev/hda2
            [size] => 4.89 GByte
            [used] => 346.95 MByte
            [free] => 4.55 GByte
            [percent] => 7
            [mount] => /mnt/dos
            [type] => vfat

    [2] => Array
            [disk] => /dev/hda4
            [size] => 15.64 MByte
            [used] => 1.79 MByte
            [free] => 13.85 MByte
            [percent] => 12
            [mount] => /mnt/scamp
            [type] => msdos


Of course, this isn't very useful by itself - what you really need to do is format it into a tabular representation, like this:

<table border="1" cellspacing="0" cellpadding="5">
<td><u>Mount point</u></td>
<td><u>Used space</u></td>
<td><u>Free space</u></td>
<td><u>Used space %</u></td>
// include class
// instantiate object
$sys = new patSysinfo(); 
// get mounted file systems
$mounts = $sys->getMount(); 
// output mount information
foreach($mounts as $m)
 echo "<tr>";
 echo "<td>" . $m['disk'] . "</td>";
 echo "<td>" . $m['mount'] . "</td>";
 echo "<td>" . $m['type'] . "</td>";
 echo "<td>" . $m['size'] . "</td>";
 echo "<td>" . $m['used'] . "</td>";
 echo "<td>" . $m['free'] . "</td>";
 echo "<td>" . $m['percent'] . " %</td>";
 echo "</tr>";

? > 

Here's the (much-friendlier) output:


>>> More PHP Articles          >>> More By icarus, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: