Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - Using Sockets in PHP
MISCELLANEOUS

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

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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Using Sockets in PHP - Making the Connection


    (Page 2 of 6 )

    You may think connecting to another Internet server is difficult but you would be wrong. You can establish a connection in just one line of PHP code. In this section I will show you how to simply connect and disconnect using sockets.

    <?php
    /*
    Arguments that fsockopen takes:
    fsockopen(Hostname/IP, Port Number, Error Number
    Variable, Error Description Variable)
    The error number variable and error description
    variable are populated only on failure of
    fsockopen.  $errno will contain the error number
    and $errdesc will contain the error description
    e.g. Server cannot be found.
    */
    $fp fsockopen"www.example.com"80$errno,
    $errdesc);
    ?>

    Now that we have established a connection to the server at example.com let's close the connection. You might be familiar with the fclose() function, we use this to close the connection.

    <?php
    $fp 
    fsockopen"www.example.com"80$errno,
    $errdesc); //establish connection
    fclose($fp); //close connection
    ?>

    Now lets move on to more useful things related to sockets on the next page.

    More Miscellaneous Articles
    More By Andrew Walsh

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap