HomePHP 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.
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.
// 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: