hostname - The name to lookup (eg. www.php.net)
type - The record type to query
class - The zone class to query
Constructs a DNS query packet and forwards the query to a nameserver configured in the system stub resolver (ie. /etc/resolv.conf). When a response is received from the DNS server, a fully populated Net_DNS_Packet object is returned that represents the response.
The resolver object contains many properties that control that behaviour of the resolver. Some of these settings are automatically read from the system resolver configuration if available. On Linux/UNIX based systems, this includes /etc/resolv.conf as well as various environment variables. This configuration is done at the time of object instantiation and can be overridden by setting the appropriate object properties.
This function will only return a Net_DNS_Packet if the ANSWER section contains resource records. Specifically, if the ANCOUNT variable in the DNS packet header is 0, query() will return 0 (note: 0, not FALSE). If you are expecting a packet without resource records in the ANSWER section, use Net_DNS_Resolver::rawQuery(). This is useful when doing manual recursion.
For a description of the returned RR data object, see Net_DNS_RR.
Resolver Configuration Object Properties:
array $nameservers
An array of nameserver IP addresses that should be queried.
int $port
The port on which nameservers should be queried. The default is 53.
array $domain
The domain in which the resolver client host resides.
array $searchlist
An array of strings containingg domains to apply to unqualified hosts passed to the resolver.
int $retry
The number of seconds between retransmission of unaswered queries
int $retrans
The number of times unanswered requests should be retried
int $recurse
Sets the value of the RD (recursion desired) bit in the header. If the RD bit is set to 0, the server will not perform recursion on the request.
int $usevc
Whether or not to use TCP (Virtual Circuits) instead of UDP If set to 0, UDP will be used unless TCP is required. TCP is required for questions or responses greater than 512 bytes.
int $debug
If set to TRUE (non-zero), debugging code will be displayed as the resolver makes the request.
Environment Variables:
RES_NAMESERVERS
Space separated list of nameserver IP addresses to query
RES_SEARCHLIST
Space separated list of domain names to add to unqualified search requests.
LOCALDOMAIN
The name of the domain
RES_OPTIONS
A space separated list of options formatted as:
optionname:value
If the value is ommited, the value defaults to 1 (true). [optionname] corresponds to an object property.
Example 48-1. Using Net_DNS_Resolver::query()
Output:
|
The following example shows a DNS query for an MX record. Note that the IP address for the mail exchanger listed within the zone is returned with the response in the additional section. The second exchanger (that is not inside this zone) is not listed. To receive this address, you must perform another query specifically for the A record using the returned hostname.
Example 48-2. Using Net_DNS_Resolver::query() to look up an MX record
Output:
|
The next example shows a more complex query with debugging information enabled. Note that the usevc option is set to TRUE. This forces the resolver to use TCP instead of UDP. This can be seen in the debug output on the send_tcp() line.
Example 48-3. Using Net_DNS_Resolver::query() with specific nameservers and options
Output:
|