PHP
  Home arrow PHP arrow Page 2 - PHP Networking
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

PHP Networking
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-09-08


    Table of Contents:
  • PHP Networking
  • DNS and PHP
  • DNS and PHP continued
  • Getting information about a domain name

  • 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


    PHP Networking - DNS and PHP
    ( Page 2 of 4 )

    PHP provides a powerful set of functions for DNS name resolution. Though the functions that are provided by PHP are limited to DNS client functionality and no server related functions are available, this is adequate since most applications will only require a name resolution service.

    Below is a list of some of the functions that are available in PHP (from the PHP manual):


    gethostbyname()

    string gethostbyname(string hostname)


    This function takes a single argument, which is the hostname of a machine, and returns a string corresponding to the IP address:


    <?php

    $host = "localhost";

    $ip = gethostbyname($host);


    echo "The IP address of $host is $ip";

    ?>


    This script displays the IP address of http://localhost as a dot-separated string of numbers. We need to obtain the IP address of a host before we can connect to it using the sockets API, as we shall soon see.


    gethostbynamel()


    array gethostbynamel(string hostname)


    Machines running operating systems that support virtual IP addresses (that is, one network card can have multiple IP addresses) can have more than one IP address associated with them. In this case, gethostbynamel() works like gethostbyname() but returns the complete list of IP addresses associated with that hostname as an array:


    <?php

    $host= "localhost";

    $ip= gethostbynamel($host);


    echo("The IP addresses of $hostare:<br>n");

    for ($i = 0; $i < count($ip); $i++) {

    echo("$ip [i] <br>n");

    }

    ?>


    Assuming that web.local.com is a machine with multiple IP addresses, this script prints a list of all those addresses.

    The other scenario where one DNS name maps onto multiple IP addresses is when certain DNS server implementations (such as BIND) support a feature known as DNS round robin. This is a rudimentary load-balancing mechanism where one DNS name maps to multiple machines (that is, IP addresses of multiple machines). The DNS queries are resolved by the server to each of these IP addresses using a round robin scheme, thereby distributing the request load between multiple machines. More information on BIND is available at http://www.isc.org/products/BIND/.


    gethostbyaddr()

    string gethostbyaddr(string ip_address)


    This function does the reverse of gethostbyname() in that, given the IP address as an argument, it returns the host name corresponding to it:


    <?php

    $ip = "127.0.0.1";

    $host= gethostbyaddr($ip);


    echo("The host name corresponding to the IP

    address $ip is $host");

    ?>


    This script displays the hostname corresponding to the IP address 127.0.0.1, which is always the localhost machine, that is, the machine on which the script was run.



     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek