Networking Functions-PHP

When using the PHP binaries for Windows that are available from http://php.net/, the getprotobyname(), getprotobynumber(), getservbyport(), and getservbyname() may not function as anticipated under Windows 2000.

DNS resource records:
  • checkdnsrr()
  • getmxrr()
Domain name/IP address lookups and conversions:
  • gethostbyaddr()
  • gethostbyname()
  • gethostbynamel()
  • ip2long()
  • long2ip()
Internet protocol and service information:
  • getprotobynumber()
  • getservbyname()
  • getprotobyname()
  • getservbyport()
PHP 3 debugger (warning: very broken!):
  • debugger_off()
  • debugger_on()
Sockets:
  • fsockopen()
  • pfsockopen()
  • socket_get_status()
  • socket_set_blocking()
  • socket_set_timeout()

    gethostbyaddr() 
    gethostbyname() 
    gethostbynamel() 
    getmxrr() 
    Example:
    Check whether a given domain name has an MX resource record
    <?php 
    $url = "http://www.php.net/"; 
    $component = parse_url ($url); 
    checkdnsrr ($component['host'], 'MX') 
        or die ('No MX record exists for <i>$component[host]</i>. 
            Did you enter the URL correctly?'); 
    echo "MX record found for <i>$component[host]</i>"; 
    ?> 

    fsockopen

    mixed fsockopen(string host, int port, [reference error_number], 
     [reference error_string], [double timeout]) 
    host
    Hostname or IP address
    port
    Port number
    error_number
    Reference to a variable that will store the system-level error number if the function fails
    error_string
    Reference to a variable that will store the system-level error message if the function fails
    timeout
    Number of seconds before the connect system call times out
    Opens a connection to a socket.
    Returns:
    File pointer identifying the open socket; FALSE on failure
    Description:
    fsockopen() attempts to open a network socket connection to the specified host and port. TCP connections are assumed by default, but UDP connections can be specified by placing udp:// at the start of the host .

    There are three optional arguments: error_number , error_string , and timeout . Both the error_number and error_string arguments must be passed as references, as in &$error_number and &$error_string. If an error occurs, these variables will contain an error code and a message. If the error number is 0, this is usually due to a problem that occurs before the socket initializes, such as an incorrect hostname.

    The timeout argument should contain the maximum number of seconds to wait for a connection before timing out.

open a socket

<?php 
$host = 'www.abcxyz.com'; 
$port = 80; 

$fp = fsockopen($host, $port, &$err_no, &$err_msg, 10) 
    or die ("Could not open a socket connection to host 
         <i>$host</i> on port <i>$port</i>. 
         The error message returned was '<i>$err_msg</i>'."); 
echo "A socket connection to host <i>$host</i> on port 
   <i>$port</i> was successfully opened." 
?>