HomePHP Page 2 - Retrieving System Information With patSysinfo
Plug and Play - 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.
patSysinfo is a PHP-based tool designed, in the author's words, to "retrieve a lot of information about the system your HTTP server is running on." Developed by Gerd Schaufelberger, it is freely available for download and is packaged as a single PHP class which can be easily included in your application.
Very simply, patSysinfo provides application developers with a set of APIs that ease the task of reading system information. This information includes the system's name and IP address, kernel version and CPU specification; it also includes data on the numbers and types of devices connected to the system, and real-time statistics on memory usage. At any given instant, patSysinfo can tell you which processes are running, and how much memory each one is consuming, together with the system's load average and number of connected users. If the system has built-in hardware sensors, patSysinfo can go even deeper, interfacing with these sensors via the lm_sensors package at http://secure.netroedge.com/~lm78/ to help you monitor the status of your hardware.
Now, there's nothing very novel or unique about patSysinfo, nor does it do anything you wouldn't be able to do yourself, given sufficient time and motivation. Its true value lies in its robust implementation of common UNIX commands (like "top", "ps", "uptime", and "uname") in PHP, thereby making it possible to integrate the output of these commands into a Web application with minimal time and fuss. Written as a PHP class, patSysinfo can substantially reduce the amount of time you spend manipulating and reading system data - especially when you have a specialized application like the one I described earlier.
Once caveat, though: patSysinfo only works with Linux systems, as it uses the special Linux /proc filesystem to obtain runtime information on the system's state. If you were planning to use this class on Windows, you should probably stop reading right now.
Before proceeding further, you should visit the patSysinfo home page at http://www.php-tools.de/ and download a copy of the latest version (1.7 at the time of writing). The package contains the main class file, documentation outlining the exposed methods and variables, and some example scripts.