PHP
  Home arrow PHP arrow Page 4 - Adding Methods to the Query Processor in PHP
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? 
Google.com  
PHP

Adding Methods to the Query Processor in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek