PHP
  Home arrow PHP arrow Page 4 - 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 - More methods ahead: defining the "Netstat()" and "getMXRecordsWin()" methods


    (Page 4 of 5 )

    As you've seen in the previous section, running commands on Windows-based systems can be quite useful for executing some well-know utilities. That's exactly the case with the "netstat" command, which can be used basically for checking the status of your different network connections. That said, here is the class method that runs that command on a Windows-based computer:

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

    As you can appreciate, this new method also uses the PHP "exec()" function, in order to execute the "netstat" command. As with the previous cases, after running this command, the output is processed as an array, which is traversed by a regular "foreach" loop, and finally returned to calling code.

    Since the above method is very easy to grasp, I won't spend a long time explaining its logic. I'll move forward and show you the last method (at least for this article) that uses the PHP "exec()" function for running Windows commands. What I referencing here is the "getMXRecordsWin()" method, which comes in handy for getting the list of MX records that correspond to a given Internet host. The source code of this method is listed below:

    // get MX records on Windows systems
    public function getMXRecordsWin(){
        $output='Retrieving MX Records...please wait.<br />';
        exec("nslookup -type=mx $this->host",$mxhosts);
        foreach($mxhosts as $mxhost){
            $output.=$mxhost.'<br />';
        }
        return $output;
    }

    In this case, the method shown above utilizes the "exec()" function for running the "nslookup" utility in conjunction with the "type" flag, in order to obtain (when applicable) the list of MX records corresponding to an Internet host. As you'll recall, this host is passed to the constructor and assigned as a class property, thus obtaining the respective MX records for it is really a no-brainer process.

    All right, at this stage I added some valuable networking methods to the "QueryProcessor" class, in order to expand its existing capabilities. Therefore, it's convenient that you see how the class looks now, after attaching the new methods. To see the full source of the class, please jump into the next section.

    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 1 hosted by Hostway
    Stay green...Green IT