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

A Nifty Device - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The running kernel stores detailed information on all devices connected to the system, and makes this information available via the /proc filesystem. This means that patSysinfo can read it. And read it, it does! The class includes three methods designed specifically to provide information on the PCI, IDE and SCSI devices attached to the system. These functions are called getPCIDevs(), getIDEDevs() and getSCSIDevs()respectively, and they're demonstrated in the following script.


<?php 
 
// include class
include("patSysinfo.php");
 
// instantiate object
$sys = new patSysinfo(); 
 
? >
 
<
html>
<
head>
</head>
<body>
  
<h2>PCI Devices</h2>
<?php 
 
// get PCI device list
$pci = $sys->getPCIDevs(); 
 
// check to see if devices exist
// then print
if (sizeof($pci) > 0)
{
 echo "<ul>";
 foreach ($pci as $p)
 {
  echo "<li>$p";
 }
 echo "</ul>";
}
else
{
 echo "None";

 
? > 
 
<
h2>IDE Devices</h2
 
<?
php 
 
// get IDE device list
$ide = $sys->getIDEDevs(); 
 
// check to see if devices exist, then print
if (sizeof($ide) > 0)
{
 echo "<ul>";
 foreach ($ide as $i)
 {
  $str = join($i, ", ");
  echo "<li>$str";
 }
 echo "</ul>";
}
else
{
 echo "None";
}
 
? > 
 
</
body>
</html>

 

Here's what the output might look like: 

patSysinfo

In a similar manner, patSysinfo also allows you to retrieve detailed data transfer statistics and information on the network interfaces that have been configured for the system. This is done via the getNetDevs() method, demonstrated below:


<?php 
 
// include class
include("patSysinfo.php"); 
 
// instantiate object
$sys = new patSysinfo(); 
 
// get list of networking interfaces
$net = $sys->getNetDevs(); 
 
// print data
print_r($net);  
 
? >

The return value of getNetDevs() is a series of arrays containing detailed statistical information about traffic on each network interface. Here's some sample output:

Array
(
    [0] => Array
        (
            [name] => sum
            [rxByte] => 749.06 kByte
            [rxPacket] => 6185
            [rxErr] => 0
            [rxDrop] => 0
            [rxFifo] => 0
            [rxFrame] => 0
            [rxCompressed] => 0
            [rxMulticast] => 0
            [txByte] => 869.15 kByte
            [txPacket] => 5135
            [txErr] => 0
            [txDrop] => 0
            [txFifo] => 0
            [txColls] => 0
            [txCarrier] => 0
            [txCompressed] => 0
        )

    [1] => Array
        (
            [name] => eth0
            [rxByte] => 749.06 kByte
            [rxPacket] => 6185
            [rxErr] => 0
            [rxDrop] => 0
            [rxFifo] => 0
            [rxFrame] => 0
            [rxCompressed] => 0
            [rxMulticast] => 0
            [txByte] => 869.15 kByte
            [txPacket] => 5135
            [txErr] => 0
            [txDrop] => 0
            [txFifo] => 0
            [txColls] => 0
            [txCarrier] => 0
            [txCompressed] => 0
        )

)

Note that this array does not include the local loopback, and that patSysinfo adds a virtual interface named "sum" which contains summary totals.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: