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." 
?> 
Related Posts:
  • PHP-Renaming Files and Directories Renaming  Files and Directories There are a few useful file and directory functions built-in to PHP which I'll cover in brief here. They include renaming and deleting files as well as listing files located in a… Read More
  • php-static variables A static variable retains its value between calls to a function but is visible only within that function. IT declare a variable static with the static keyword. function test_counter ( ) { static $counter = 0; $counte… Read More
  • php best tutorial-php variables PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are either in PHP's global symbol table or … Read More
  • php implode array elements php implode array elements Join array elements with a string string. implode(string, arraypieces) Returns a string containing a string representation of all the array elements in the same order,  string between each e… Read More
  • Drupal Bootstrap Process Drupal Bootstrap Process? Drupal bootstraps itself on every request by going through a series of bootstrap phases. These phases aredefined in bootstrap.inc and proceed. Configuration Sets global variables used throughout th… Read More
  • php-use the header() function-php An HTTP (HyperText Transfer Protocol) header is used to send information back and forth between the server and the client (the Web browser). Normally this information is in the form of HTML, which is why the address for Web … Read More
  • Advanced Database Techniques PEAR DB is the database primitives shown earlier; it provides several shortcut functions for fetching result rows, as well as a unique row ID system and separate prepare/execute steps that can improve the performance of re… Read More
  • php Sessions page Php Sessions are used to help maintain the values of variables across multiple web pages. This is done by creating a unique session ID that is sent to the client browser. The browser then sends the unique ID back on eac… Read More
  • Php Operators PHP Operators The following table lists the operators from highest to lowest precedence. Operators A !, ~, ++, --, @ Right *, /, % Left +, -, . Left <<, >> Left <… Read More
  • php-Error Control Operators PHP gives one error control operator: the at sign (@).Any error messages that might be generated by that expression will be ignored. If you have set a custom error handler function with set_error_handler() then it will s… Read More
  • Web-Based MySQL Administration Web-Based MySQL Administration At http://phpwizard.net/phpMyAdmin you will find a PHP Web application that can help you manage MySQL. It enables you to manage a MySQL database using a browser and makes administrative work… Read More
  • Php Networking Functions There are many functions in php to convert or look up domain name, IP address, protocol, and service information. Domain name/IP address lookups and conversions gethostbynamel() gethostbyname() gethostbyaddr() … Read More
  • PHP variable-related functions Cast a value from one type to other type:- doubleval(), intval(), strval() Set  type of a variable:- settype() Verify  the type of a variable:- is_array(), is_bool(), is_double(), is_float(), is_int(), … Read More
  • php urlencode - Make a strong GET Query String  php urlencode URL-encodes a string, converting spaces into plus (+ ) signs. urlencode() makes a string safe to use as part of a URL. It does this by encoding every character within the string that may be misi… Read More
  • pass information from page to page-best seo Adding information to the URL: You can add certain information to the end of the URL of the new page, and PHP puts the information into builtin arrays that you can use in the new page. This method is most appropriate when yo… Read More