"PHPresolver" - PHP DNS resolver library

PHPresolver class library reference

version 1.1
Copyright(c) 2001, 2002 Moriyoshi Koizumi. All Rights Reserved.

class DNSResolver

DNS resolver object.


DNSResolver( string nameserver [, int port] [, int timeout] )

specifies a domain name or an IP address of the domain name server(DNS) used for domain name resolution.
port (optional)
specifies the number of the port that accepts DNS service. Default value is 53.
timeout (optional)
specifies the connection timeout in nano seconds. default value is 10000000 (1 second).


DNSAnswer sendQuery( DNSQuery dnsquery [, boolean useTCP] )

specifies an DNSQuery object which contains information to query to the name server.
useTCP (optional)
This flag forces the resolver to use TCP connection for querying a server. By default it uses UDP connection and switches to use TCP when it is necessary.
[return value]
A DNSAnswer Object

class DNSName

The object that holds a series of subdomains, i.e. a domain name.


DNSName( array labels )

An array of sub-domain strings. For example, domain name "a.b.c" is represented as:
array[0] => 'a'
array[1] => 'b'
array[2] => 'c'
array[3] => '' (void string)
Literal IP addresses should be represented as subdomains of ARPA domain.


DNSName DNSName::newFromString( string domainname )

specifies a domain name which will be converted into an DNSName object.
Acceptable formats are listed below; (literal IPv4 address format) (defined in RFC1035; the value is same as above)
www.example.com (generic domain name)
ffff:0:4567:89ab:fdfa:132:0:413 (literal IPv6 address format) (defined in RFC1886; same as above)
ffff:: (literal IPv6 address format)

and those formats are currently unsupported;
\[xffff0123456789abfdfa013200000413/128].IP6.ARPA (defined in RFC2874)
\[x89abfdfa013200000413/80].\[xffff01234567/48].IP6.ARPA (same as above)
[return value]
an DNSName Object

boolean isRealDomainName()

[return value]
true if the domain name this object represents does not belong to ARPA domain.

string asOctets()

[return value]
Binary representation of sub-domains.

string getCanonicalName()

[return value]
String representation of sub-domains.

class DNSAnswer

The object that holds responses from the name server.


DNSAnswer( int stream, int limit )

specifies file pointer returned by fsockopen.
specifies the maximum number of bytes to read from the stream.
This object should be created via DNSResolver::sendQuery() method. To directly instantiate this object with a new operator is not a generic way.
If the actual message length is found exceeding the limit length while reading the response message stream, the rest would be ignored and the parser would return an error status.


result code returned by the name server. the value has following meanings: (mostly cited from RFC1035)
value meaning description
0 no error condition
The query was successfully accepted and interpreted by the name server.
1 format error The name server was unable to interpret the query.
2 server failure
The name server was unable to process this query due to a problem with the name server.
3 name error
Meaningful only for responses from an authoritative name server, this code signifies that the domain name referenced in the query does not exist.
4 not implemented
The name server does not support the requested kind of query.
5 refused
The name server refuses to perform the specified operation for policy reasons. For example, a name server may not wish to provide the information to the particular requester, or a name server may not wish to perform a particular operation (e.g., zone transfer) for particular data.
6-15 reserved Reserved for future use.
an array of DNSRecord objects that hold the same query record as given to DNSQuery object.
an array of DNSRecord objects that hold ANSWER records returned by the name server.
an array of DNSRecord objects that hold AUTHORITY records returned by the name server.
an array of DNSRecord objects that hold ADDITIONAL records returned by the name server.

class DNSQuery

The object that holds a query to ask the name server.


DNSQuery( DNSRecord dnsrecord [, int flags ] )

specifies a query to ask the name server that is described by a DNSRecord object.
specifies the quering option flags. The flags consists of following bitfields:
name description
DNS_HEADERSPEC_RECURSION_DESIRED (default) If set, it directs the name server to pursue the query recursively over the reachable name servers. This bit is copied into the query record of response message.


string asOctets()

[return value]
binary representation of the query.

class DNSRecord

The object that represents a RECORD, a unit of meaningful information to be exchanged between the name server and the client.


DNSRecord( DNSName name, int type [, int dclass] [, int ttl] [, array specific_fields] )

DNSName object for a domain name
DNS record type.
value meaning
DNS_RECORDTYPE_A a host address
DNS_RECORDTYPE_NS an authoritative name server
DNS_RECORDTYPE_SOA start of authority zone
DNS_RECORDTYPE_PTR a domain name pointer
DNS_RECORDTYPE_MX mail exchange
DNS_RECORDTYPE_AAAA a IPv6 host address
DNS_RECORDTYPE_ANY (used only for querying) to retrieve any records associated with the name
dclass (optional)
This must be the value of DNS_CLASS_INTERNET.
ttl (optional)
(abbreviation for time-to-live) The period in seconds during which the (retrieved) information should be cached. the value 0 means that no cache is to be performed.
specific_fields (optional)
Type-specific fields.


see the "constructor" section.
An associative array of type-specific fields.
key name type value
A DNSName object that represents an IP address.
A DNSName object that represents a domain name.
preference DNS_RECORDTYPE_MX An integer value that specifies how much preferred the host is for mail exchange among others. The lower value means the stronger preference.
exchange DNS_RECORDTYPE_MX A DNSName object that represents the domain name of the host to use for mail exchange.
resp_person DNS_RECORDTYPE_SOA The mail address of the person responsible for this zone.
source DNS_RECORDTYPE_SOA A DNSName object that specifies the domain name of the master name server, from which the zone information is transferred.
serial DNS_RECORDTYPE_SOA An integer value with which the slave(secondary) server identifies the revision of the zone information transferred from the master(primary) name server.
refresh DNS_RECORDTYPE_SOA An integer value that specifies in seconds the interval after which the slaveserver tries to check the master name server for the updated zone information.
retry DNS_RECORDTYPE_SOA An integer value that specifies in seconds the interval after which the slave server retries zone transfer when the previous try failed.
expire DNS_RECORDTYPE_SOA An integer value that specifies in seconds the period during which the slave server sees the zone information is valid. After the expiry, the server will stop sending any records of the zone in response to the queries until the entire zone information is updated.
minttl DNS_RECORDTYPE_SOA An integer value that specifies in seconds the minimum time the DNS records should be cached for.


mixed getTypeSpecificField( string name )

specifies a field name. The acceptable names depend on the record type.
[return value]
Value of the field.