Network Functions
Network Functions
fsockopen
Name
fsockopen — Open Internet or Unix domain socket connection.
Description
int fsockopen(string hostname, int port, int [errno], string [errstr]);
Opens an Internet domain socket connection to hostname on port port and returns a file pointer, which may be used by fgets, fgetss, fputs, and fclose. If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that ocurred on the system-level connect() call. If the returned errno is 0, but the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments should be passed by reference.
If port is 0 and the operating system supports Unix domain sockets, hostname will be used as the filename of a Unix domain socket to connect to.
The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using the set_socket_blocking.
Example 1. fsockopen example
$fp = fsockopen("www.php.net", 80, &$errno, &$errstr); if(!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($fp,"GET / HTTP/1.0\n\n"); while(!feof($fp)) {
echo fgets($fp,128);
}
fclose($fp);
}
set_socket_blocking
Name
set_socket_blocking — Set blocking/non-blocking mode on a socket
Description
int set_socket_blocking(int socket descriptor, int mode);
If mode is false, the given socket descriptor will be switched to non-blocking mode, and if true, it will be switched to blocking mode. This affects calls like fgets that read from the socket. In non-blocking mode an fgets() call will always return right away while in blocking mode it will wait for data to become available on the socket.
gethostbyaddr
Name
gethostbyaddr — Get the Internet host name corresponding to a given IP address.
Description
string gethostbyaddr(string ip_address);
Returns the host name of the Internet host specified by ip_address. If an error occurs, returns
ip_address.
See also gethostbyname.
gethostbyname
Name
gethostbyname — Get the IP address corresponding to a given Internet host name.
Description
string gethostbyname(string hostname);
Returns the IP address of the Internet host specified by hostname. See also gethostbyaddr.
gethostbynamel
Name
gethostbynamel — Get a list of IP addresses corresponding to a given Internet host name.
Description
array gethostbynamel(string hostname);
Returns a list of IP addresses to which the Internet host specified by hostname resolves.
See also gethostbyname, gethostbyaddr, checkdnsrr, getmxrr, and the named(8) manual page.
checkdnsrr
Name
checkdnsrr — Check DNS records corresponding to a given Internet host name or IP address.
Description
int checkdnsrr(string host, string [type]);
Searches DNS for records of type type corresponding to host. Returns true if any records are found; returns false if no records were found or if an error occurred.
type may be any one of: A, MX, NS, SOA, PTR, CNAME, or ANY. The default is MX.
host may either be the IP address in dotted-quad notation or the host name.
See also getmxrr, gethostbyaddr, gethostbyname, gethostbynamel, and the named(8) manual page.
getmxrr
Name
getmxrr — Get MX records corresponding to a given Internet host name.
Description
int getmxrr(string hostname, array mxhosts, array [weight]);
Searches DNS for MX records corresponding to hostname. Returns true if any records are found; returns false if no records were found or if an error occurred.
A list of the MX records found is placed into the array mxhosts. If the weight array is given, it will be filled with the weight information gathered.
See also checkdnsrr, gethostbyname, gethostbynamel, gethostbyaddr, and the named(8) manual page.
openlog
Name
openlog — open connection to system logger
Description
int openlog(string ident, int option, int facility);
openlog opens a connection to the system logger for a program. The string ident is added to each message. Values for option and facility are given in the next section. The use of openlog() is optional; It will automatically be called by syslog if necessary, in which case ident will default to false. See also syslog and closelog.
syslog
Name
syslog — generate a system log message
Description
int syslog(int priority, string message);
syslog generates a log message that will be distributed by the system logger. priority is a combination of the facility and the level, values for which are given in the next section. The remaining argument is the message to send, except that the two characters %m will be replaced by the error message string (strerror) corresponding to the present value of errno.
closelog
Name
closelog — close connection to system logger
Description
int closelog(void);
closelog closes the descriptor being used to write to the system logger. The use of closelog is optional.
debugger_on
Name
debugger_on — enable internal PHP debugger
Description
int debugger_on(string address);
Enables the internal PHP debugger, connecting it to address. The debugger is still under development.
debugger_off
Name
debugger_off — disable internal PHP debugger
Description
int debugger_off(void);
Disables the internal PHP debugger. The debugger is still under development.