PHP
  Home arrow PHP arrow Page 3 - Adding Methods to the Query Processor ...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Adding Methods to the Query Processor in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2006-05-24

    Table of Contents:
  • Adding Methods to the Query Processor in PHP
  • Reviewing previous PHP networking functions: a quick look at the "QueryProcessor" class
  • Adding more functionality to the "QueryProcessor" class: defining the "Ping()" and "IpConfig()" methods
  • More methods ahead: defining the "Netstat()" and "getMXRecordsWin()" methods
  • Gluing the pieces together: listing the full source code of the "QueryProcessor" class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Adding Methods to the Query Processor in PHP - Adding more functionality to the "QueryProcessor" class: defining the "Ping()" and "IpConfig()" methods


    (Page 3 of 5 )

    The first method that I will add to the class is "IpConfig()," which, as the name clearly suggests, is responsible for executing the "ipconfig" Windows-based utility. In case you didn't know, this program will let you know the network settings of your Windows system, including the IP address, subnet mask, DNS suffixes, default gateway, and so on for each of the network adapters installed on your computer.

    Having described the functionality of the "ipconfig" Windows utility, take a look at the method below, which runs this command on a Windows machine:

    // execute 'ipconfig' command on Windows systems
    public function IpConfig(){
        $output='Running ipconfig command...Please wait.<br />';
        exec('ipconfig',$lines);
        foreach($lines as $line){
            $output.=$line.'<br />';
        }
        return $output;
    }

    In this case, the above "Ipconfig()" method uses the "exec()" PHP built-in function, in order to perform the homonymous Windows utility. As you know, this function allows the execution of commands on the server (provided that you have the right permissions) and returns the corresponding results as an array structure.

    After executing the "ipconfig" command, the output is returned to calling code, simply by iterating over the output array returned by the "exec()" function. Evidently, this method is really simple to read and code, thus I'll move on to the next one, "Ping()," which runs the popular "ping" command on Windows-based systems. Please take a look at the way this method is defined:

    // execute 'ping' command on Windows systems
    public function Ping(){
        $output='Running ping command...Please wait.<br />';
        exec('ping '.$this->host,$lines);
        foreach($lines as $line){
            $output.=$line.'<br />';
        }
        return $output;
    }

    As illustrated in the above code block, the "Ping()" method looks nearly identical to the previous one. Of course, the only difference rests on the type of Window command executed, which in this case is the famous "ping" utility. Similar to the "IpConfig()" method that you learned before, this method first uses the "exec()" PHP function, in order to run the "ping" program, and next returns the result as an array.

    Due to the numerous similarities exposed by the two methods, it's possible to merge them into one and avoid writing additional code. However, I want you to learn each method as a separate block of code, since it's much simpler to read and understand.

    Now, after defining the prior methods, I'll code two new methods in the next section, which also use the "exec()" PHP native function for doing its business on Windows systems. To learn more on this please keep on reading.

    More PHP Articles
    More By Alejandro Gervasio


       · In this second article of the series, you'll see how to add more methods to the...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





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