Retrieving System Information With patSysinfo - A Nifty Device (
Page 6 of 9 )
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:

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.