PHP
  Home arrow PHP arrow Page 3 - Retrieving System Information With patSysinfo
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Retrieving System Information With patSysinfo
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 19
    2004-02-16


    Table of Contents:
  • Retrieving System Information With patSysinfo
  • Plug and Play
  • What's in a Name?
  • Up and at 'Em
  • Carrying the Load
  • A Nifty Device
  • Running Out of RAM
  • Mounting Up
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Retrieving System Information With patSysinfo - What's in a Name?
    ( Page 3 of 9 )

    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.


    <?php
    // include class
    include("patSysinfo.php");
     
    // 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 192.168.0.2

    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
     include("patSysinfo.php");

    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT