Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - Using Sockets in PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
MISCELLANEOUS

Using Sockets in PHP
By: Andrew Walsh
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2004-06-24

    Table of Contents:
  • Using Sockets in PHP
  • Making the Connection
  • Sending The Request
  • Searching for a Page
  • Whois Example
  • Conclusion

  • 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


    Using Sockets in PHP - Whois Example


    (Page 5 of 6 )

    So you have learned how to connect to servers, fetch results, loop through results and finally close connections. So I thought I would include a more practical example in this section and I chose to do a whois example which connects to certain whois servers and checks for a record for a certain domain.

    <?php
    extract
    ($_POST); 
    function 
    whois($domain,$ext){ 
    $url=$domain.$ext
    /*
    Use a switch() statement to determine which whois 
    server is the best to use for the entered domain.
    */
    switch($ext){ 
    case 
    ".co.uk"
    $whois "whois.nic.uk"
    break; 
    case 
    ".com"
    $whois "whois.networksolutions.com"
    break; 
    case 
    ".fr"
    $whois "whois.nic.fr"
    break; 
    case 
    ".biz"
    $whois "whois.biz"
    break; 
    default: 
    $whois "whois.networksolutions.com"

    if (
    trim($url) &lt;&gt"") { 
      
    $url trim($url);
    /*
    Open the connection to the above whois server
    */ 
    $f fsockopen($whois43$errno$errstr30); 
      if (!
    $f) { 
         echo 
    "Connection To Server Failed ($errno)"
      } else {
    /*
    Send the domain to the server and return the
    results
    */ 
         
    fputs($f"$url&#92;r&#92;n"); 
         print 
    "&lt;pre&gt;&#92;r&#92;n"
       while (!
    feof($f)) { 
            echo 
    fread($f,128); 
         } 
        print 
    "&lt;/pre&gt;";
    /*
    Use fclose to close the connection to the whois 
    server
    */ 
         
    fclose($f); 
      } 
    }else{ 
    echo 
    "Invalid domain entered"

    }
    ?>

    Notice I have written this code in a function so it is more practical and reusable than the other examples in this tutorial. They can be coded up into a function with relative ease.

    More Miscellaneous Articles
    More By Andrew Walsh


       · Great Job, Andrew!Most of the socket tutorials I've seen demonstrate sockets by...
       · Thanks very much tim
       · An Excellent piece of work, explained so well. Made such a big topic look so simple....
       · Thanks for the comments.
       · Hello Andrew!Can you tell me more regarding this request please:$request =...
       · A HEAD request only sends the headers to the browser/cliet. It does not send any...
       · It is extremely difficult to read the topic .Please enlarge the code.
     

    MISCELLANEOUS ARTICLES

    - Install Slackware on Your Old PC
    - Firefox Plugins You`re Not Using (and Should...
    - Working with MP3 ID3 Tags in FTP Server Usin...
    - How Switching to Linux Can Make Your Computi...
    - Set Up Your Home Office on Linux: a Guide fo...
    - Putty File Transfer Commands in SSH Protocol
    - Setting Up Ubuntu for Your Home Office
    - Installing Mint Linux
    - Crucial Traits of Awk
    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell





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