File: dns-get-record.xml

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (527 lines) | stat: -rw-r--r-- 15,546 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 297028 $ -->
<refentry xml:id="function.dns-get-record" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>dns_get_record</refname>
  <refpurpose>Fetch DNS Resource Records associated with a hostname</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>array</type><methodname>dns_get_record</methodname>
   <methodparam><type>string</type><parameter>hostname</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>type</parameter><initializer>DNS_ANY</initializer></methodparam>
   <methodparam choice="opt"><type>array</type><parameter role="reference">authns</parameter></methodparam>
   <methodparam choice="opt"><type>array</type><parameter role="reference">addtl</parameter></methodparam>
  </methodsynopsis>
  <para>
   Fetch DNS Resource Records associated with the given
   <parameter>hostname</parameter>.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>hostname</parameter></term>
     <listitem>
      <para>
       <parameter>hostname</parameter> should be a valid DNS hostname such
       as "<literal>www.example.com</literal>". Reverse lookups can be generated
       using <literal>in-addr.arpa</literal> notation, but
       <function>gethostbyaddr</function> is more suitable for
       the majority of reverse lookups.
      </para>
      <note>
       <para>
        Per DNS standards, email addresses are given in <literal>user.host</literal> format (for
        example: <literal>hostmaster.example.com</literal> as opposed to <literal>hostmaster@example.com</literal>),
        be sure to check this value and modify if necessary before using it
        with a functions such as <function>mail</function>.
       </para>
      </note>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>type</parameter></term>
     <listitem>
      <para>
       By default, <function>dns_get_record</function> will search for any
       resource records associated with <parameter>hostname</parameter>. 
       To limit the query, specify the optional <parameter>type</parameter>
       parameter. May be any one of the following:
       <constant>DNS_A</constant>, <constant>DNS_CNAME</constant>,
       <constant>DNS_HINFO</constant>, <constant>DNS_MX</constant>,
       <constant>DNS_NS</constant>, <constant>DNS_PTR</constant>,
       <constant>DNS_SOA</constant>, <constant>DNS_TXT</constant>,
       <constant>DNS_AAAA</constant>, <constant>DNS_SRV</constant>,
       <constant>DNS_NAPTR</constant>, <constant>DNS_A6</constant>,
       <constant>DNS_ALL</constant> or <constant>DNS_ANY</constant>.
      </para>
      <note>
       <para>
        Because of eccentricities in the performance of libresolv
        between platforms, <constant>DNS_ANY</constant> will not
        always return every record, the slower <constant>DNS_ALL</constant>
        will collect all records more reliably.
       </para>
      </note>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>authns</parameter></term>
     <listitem>
      <para>
       Passed by reference and, if given, will be populated with Resource
       Records for the <emphasis>Authoritative Name Servers</emphasis>.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>addtl</parameter></term>
     <listitem>
      <para>
       Passed by reference and, if given, will be populated with any
       <emphasis>Additional Records</emphasis>.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   This function returns an array of associative arrays.  Each associative array contains
   <emphasis>at minimum</emphasis> the following keys:
   <table>
    <title>Basic DNS attributes</title>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>Attribute</entry>
       <entry>Meaning</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>host</entry>
       <entry>
        The record in the DNS namespace to which the rest of the associated data refers.
       </entry>
      </row>
      <row>
       <entry>class</entry>
       <entry>
        <function>dns_get_record</function> only returns Internet class records and as
        such this parameter will always return <literal>IN</literal>.
       </entry>
      </row>
      <row>
       <entry>type</entry>
       <entry>
        String containing the record type.  Additional attributes will also be contained
        in the resulting array dependant on the value of type. See table below.
       </entry>
      </row>
      <row>
       <entry>ttl</entry>
       <entry>
        <literal>"Time To Live"</literal> remaining for this record. This will <emphasis>not</emphasis> equal
        the record's original ttl, but will rather equal the original ttl minus whatever
        length of time has passed since the authoritative name server was queried.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
  <para>
   <table>
    <title>Other keys in associative arrays dependant on 'type'</title>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>Type</entry>
       <entry>Extra Columns</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry><literal>A</literal></entry>
       <entry>
        <literal>ip</literal>: An IPv4 addresses in dotted decimal notation.
       </entry>
      </row>
      <row>
       <entry><literal>MX</literal></entry>
       <entry>
        <literal>pri</literal>: Priority of mail exchanger.
        Lower numbers indicate greater priority.
        <literal>target</literal>: FQDN of the mail exchanger.
        See also <function>dns_get_mx</function>.
       </entry>
      </row>
      <row>
       <entry><literal>CNAME</literal></entry>
       <entry>
        <literal>target</literal>: FQDN of location in DNS namespace to which
        the record is aliased.
       </entry>
      </row>
      <row>
       <entry><literal>NS</literal></entry>
       <entry>
        <literal>target</literal>: FQDN of the name server which is authoritative
        for this hostname.
       </entry>
      </row>
      <row>
       <entry><literal>PTR</literal></entry>
       <entry>
        <literal>target</literal>: Location within the DNS namespace to which
        this record points.
       </entry>
      </row>
       <row>
       <entry><literal>TXT</literal></entry>
       <entry>
        <literal>txt</literal>: Arbitrary string data associated with this record.
       </entry>
      </row>
      <row>
       <entry><literal>HINFO</literal></entry>
       <entry>
        <literal>cpu</literal>: IANA number designating the CPU of the machine
        referenced by this record.
        <literal>os</literal>: IANA number designating the Operating System on
        the machine referenced by this record.
        See IANA's <link xlink:href="&url.iana.system-names;"><literal>Operating System
        Names</literal></link> for the meaning of these values.
       </entry>
      </row>
      <row>
       <entry><literal>SOA</literal></entry>
       <entry>
        <literal>mname</literal>: FQDN of the machine from which the resource
        records originated.
        <literal>rname</literal>: Email address of the administrative contain
        for this domain.
        <literal>serial</literal>: Serial # of this revision of the requested
        domain.
        <literal>refresh</literal>: Refresh interval (seconds) secondary name
        servers should use when updating remote copies of this domain.
        <literal>retry</literal>: Length of time (seconds) to wait after a
        failed refresh before making a second attempt.
        <literal>expire</literal>: Maximum length of time (seconds) a secondary
        DNS server should retain remote copies of the zone data without a
        successful refresh before discarding.
        <literal>minimum-ttl</literal>: Minimum length of time (seconds) a
        client can continue to use a DNS resolution before it should request
        a new resolution from the server.  Can be overridden by individual
        resource records.
       </entry>
      </row>
      <row>
       <entry><literal>AAAA</literal></entry>
       <entry>
        <literal>ipv6</literal>: IPv6 address
       </entry>
      </row>
      <row>
       <entry><literal>A6</literal>(PHP &gt;= 5.1.0)</entry>
       <entry>
        <literal>masklen</literal>: Length (in bits) to inherit from the target
        specified by <parameter>chain</parameter>.
        <literal>ipv6</literal>: Address for this specific record to merge with
        <parameter>chain</parameter>.
        <literal>chain</literal>: Parent record to merge with
        <parameter>ipv6</parameter> data.
       </entry>
      </row>
      <row>
       <entry><literal>SRV</literal></entry>
       <entry>
        <literal>pri</literal>: (Priority) lowest priorities should be used first.
        <literal>weight</literal>: Ranking to weight which of commonly prioritized
        <parameter>targets</parameter> should be chosen at random.
        <literal>target</literal> and <literal>port</literal>: hostname and port
        where the requested service can be found.
        For additional information see: <link xlink:href="&url.rfc;2782">RFC 2782</link>
       </entry>
      </row>
      <row>
       <entry><literal>NAPTR</literal></entry>
       <entry>
        <literal>order</literal> and <literal>pref</literal>: Equivalent to
        <parameter>pri</parameter> and <parameter>weight</parameter> above.
        <literal>flags</literal>, <literal>services</literal>, <literal>regex</literal>,
        and <literal>replacement</literal>: Parameters as defined by
        <link xlink:href="&url.rfc;2915">RFC 2915</link>.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>5.3.0</entry>
       <entry>
         This function is now available on Windows platforms.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Using <function>dns_get_record</function></title>
    <programlisting role="php">
<![CDATA[
<?php
$result = dns_get_record("php.net");
print_r($result);
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => MX
            [pri] => 5
            [target] => pair2.php.net
            [class] => IN
            [ttl] => 6765
        )

    [1] => Array
        (
            [host] => php.net
            [type] => A
            [ip] => 64.246.30.37
            [class] => IN
            [ttl] => 8125
        )

)
]]>
    </screen>
   </example>
   <example>
    <title>Using <function>dns_get_record</function> and DNS_ANY</title>
    <para>
     Since it's very common to want the IP address of a mail server
     once the MX record has been resolved, <function>dns_get_record</function>
     also returns an array in <parameter>addtl</parameter> which
     contains associate records.  <parameter>authns</parameter>
     is returned as well containing a list of authoritative name
     servers.
    </para>
    <programlisting role="php">
<![CDATA[
<?php
/* Request "ANY" record for php.net,
   and create $authns and $addtl arrays
   containing list of name servers and
   any additional records which go with
   them */
$result = dns_get_record("php.net", DNS_ANY, $authns, $addtl);
echo "Result = ";
print_r($result);
echo "Auth NS = ";
print_r($authns);
echo "Additional = ";
print_r($addtl);
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
Result = Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => MX
            [pri] => 5
            [target] => pair2.php.net
            [class] => IN
            [ttl] => 6765
        )

    [1] => Array
        (
            [host] => php.net
            [type] => A
            [ip] => 64.246.30.37
            [class] => IN
            [ttl] => 8125
        )

)
Auth NS = Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => remote1.easydns.com
            [class] => IN
            [ttl] => 10722
        )

    [1] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => remote2.easydns.com
            [class] => IN
            [ttl] => 10722
        )

    [2] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => ns1.easydns.com
            [class] => IN
            [ttl] => 10722
        )

    [3] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => ns2.easydns.com
            [class] => IN
            [ttl] => 10722
        )

)
Additional = Array
(
    [0] => Array
        (
            [host] => pair2.php.net
            [type] => A
            [ip] => 216.92.131.5
            [class] => IN
            [ttl] => 6766
        )

    [1] => Array
        (
            [host] => remote1.easydns.com
            [type] => A
            [ip] => 64.39.29.212
            [class] => IN
            [ttl] => 100384
        )

    [2] => Array
        (
            [host] => remote2.easydns.com
            [type] => A
            [ip] => 212.100.224.80
            [class] => IN
            [ttl] => 81241
        )

    [3] => Array
        (
            [host] => ns1.easydns.com
            [type] => A
            [ip] => 216.220.40.243
            [class] => IN
            [ttl] => 81241
        )

    [4] => Array
        (
            [host] => ns2.easydns.com
            [type] => A
            [ip] => 216.220.40.244
            [class] => IN
            [ttl] => 81241
        )

)
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    For compatibility with versions before this function was implemented 
    on such platforms as Windows, *BSD and MAC. Try the
    <link xlink:href="&url.php.pear;">PEAR</link> class
    <link xlink:href="&url.pear.package;Net_DNS">Net_DNS</link>.
   </para>
  </note>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>dns_get_mx</function></member>
    <member><function>dns_check_record</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->