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

What's in a Name? - 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



Now that the hard sell is over and you're (hopefully) all set up with patSysinfo, let's take a simple example to see how it works.

// include class
// instantiate object
$sys = new patSysinfo();
// get hostname
 $name = $sys->getHostName();
// get host IP address
 $ip = $sys->getHostIp();
// output values 
echo "This system is named $name and has IP address $ip";
? >

Here's the output:

This system is named olympus.local.net and has IP address

Let's dissect this to see how it works.

1. The first step is, obviously, to include all the relevant files for the class to work.

// include class

Once that's done, I can safely create an object of the patSysinfo class.

// instantiate object
$sys = new patSysinfo();

This object instance will serve as the central source for all system information, allowing me to do all kinds of nifty things with it.

2. Next, the object's getHostName() and getHostIp() methods are used to obtain the system's host name and IP address respectively.

// get host name
$name = $sys->getHostName();
// get host IP address
$ip = $sys->getHostIp();

Most of the patSysinfo API calls look like this: the word "get" followed by the information that is required. In the example above, the object first looks up the file "/proc/sys/kernel/hostname" for the current hostname, and then obtains the IP address using the host name and the gethostbyname() PHP function

4. Finally, all that's left is to actually use the data retrieved by the methods - in this case, print it all to the standard output device.

// output values 
echo "This system is named $name and has IP address $ip";

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