Should I call dns_get_record () multiple times, or once with DNS_ANY?

For PHP's dns_get_record () function, does using DNS_ANY

to retrieve all records make more or less HTTP (or any other protocol) requests than calling types separately?

// Is just 1 request? Or many requests (1 per each record type)?
dns_get_record('example.com', DNS_ANY);

VS

// 3 total requests?
dns_get_record('example.com', DNS_A);
dns_get_record('example.com', DNS_AAAA);
dns_get_record('example.com', DNS_MX); 

      

Basically, I would like to minimize network requests if I can, but I have no idea how dns_get_record () works under the hood.

Since the documentation states that it DNS_ANY

doesn't always return all records, I figured I could try to name the types I want to get in order to get more predictable results. But at the same time it makes 3 individual requests for one request with DNS_ANY. It's true?

Btw, DNS_ALL

or DNS_A + DNS_AAAA + DNS_MX

will return false if any of the types are null, so I can't seem to do that.

+3


source to share


1 answer


Obtaining information separately for each type is inefficient because it involves multiple requests, whereas using the DNS_ANY parameter with dns_get_record () gets all the information in only one request. DNS_ANY is a parameter that comes in handy for querying the DNS server for information. With this particular parameter, you can get some information.

You can see this for yourself if you try to use a utility like "dig" on the Linux command line for a domain like gmail.com like this:

dig gmail.com ANY

The output looks like this:



`;; QUESTION SECTION:
;gmail.com.                     IN      ANY

;; ANSWER SECTION:
gmail.com.              2386    IN      MX      30 alt3.gmail-smtp-in.l.google.c                                                                              om.
gmail.com.              2386    IN      MX      40 alt4.gmail-smtp-in.l.google.c                                                                              om.
gmail.com.              2386    IN      MX      5 gmail-smtp-in.l.google.com.
gmail.com.              2386    IN      MX      10 alt1.gmail-smtp-in.l.google.c                                                                              om.
gmail.com.              2386    IN      MX      20 alt2.gmail-smtp-in.l.google.c                                                                              om.
gmail.com.              85186   IN      SOA     ns1.google.com. dns-admin.google                                                                              .com. 2012061200 21600 3600 1209600 300
gmail.com.              81180   IN      NS      ns3.google.com.
gmail.com.              81180   IN      NS      ns4.google.com.
gmail.com.              81180   IN      NS      ns1.google.com.
gmail.com.              81180   IN      NS      ns2.google.com.

;; AUTHORITY SECTION:
gmail.com.              81180   IN      NS      ns2.google.com.
gmail.com.              81180   IN      NS      ns3.google.com.
gmail.com.              81180   IN      NS      ns4.google.com.
gmail.com.              81180   IN      NS      ns1.google.com.

;; ADDITIONAL SECTION:
ns1.google.com.         223708  IN      A       216.239.32.10
ns2.google.com.         223708  IN      A       216.239.34.10
ns3.google.com.         223708  IN      A       216.239.36.10
ns4.google.com.         223708  IN      A       216.239.38.10

;; Query time: 4 msec
[snip] 

      

PHP dns_get_record () behaves like a dig utility, i.e. communicates with the dns server and makes the request. A parameter like "DNS_ANY" is beneficial because it gets everything at once. Since the digging took 4ms, I guess dns_get_record () will take about the same, or maybe a little longer. Since the DNS_ANY parameter may provide more information than is required, you can, for example, restrict this query to only "MX" records using DNS_MX with the function.

If you're curious about the internal PHP code for this function, take a look here . The internal source code is usually written in the C programming language.

If you want to know more about how DNS works, especially when using PHP, see my article for php | architect named Email Checker (June 2008).

+1


source







All Articles