Checks whether DNS records of a chosen type are available for a host.
What Is checkdnsrr() in PHP?
Checks whether DNS records of a chosen type are available for a host.
Its syntax is:
checkdnsrr(string $hostname, string $type = "MX"): bool
Parameters:
$hostname— Accepted as string; required argument.$type— Accepted as string; optional default "MX".
Return type: bool. DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.
Availability: Requires network DNS access.
Example 1: Basic Usage
<?php
var_dump(checkdnsrr("example.com", "A"));
Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.
Example 2: A Different Input
<?php
var_dump(checkdnsrr("example.com", "MX"));
Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.
Practical Example: Applying It in a Program
<?php
$hostname = "example.com"; foreach (["A", "AAAA", "MX"] as $recordType) { echo "$recordType: " . (checkdnsrr($hostname, $recordType) ? "found" : "absent") . PHP_EOL; }
Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.
Important Behavior and Edge Cases
- Key behavior: DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.
- Environment: Requires network DNS access.
Comparison With Related Functions
| Function | Purpose |
|---|---|
checkdnsrr() | Checks whether DNS records of a chosen type are available for a host. |
dns_get_record() | dns_get_record() returns DNS record details; checkdnsrr() answers whether a chosen record type exists. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy | DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy. |
Key Takeaways
- Checks whether DNS records of a chosen type are available for a host.
- DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.
- Requires network DNS access.
Summary: DNS answers depend on network conditions and do not prove that a service is accessible or trustworthy.