Content · Programming · PHP

PHP dns_check_record() Function: Usage and Examples

Learn how PHP dns_check_record works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Checks for the presence of a DNS record; this is an alias of checkdnsrr().

What Is dns_check_record() in PHP?

Checks for the presence of a DNS record; this is an alias of checkdnsrr().

Its syntax is:

dns_check_record(string $hostname, string $type = "MX"): bool

Parameters:

  • $hostname — Accepted as string; required argument.
  • $type — Accepted as string; optional default "MX".

Return type: bool. DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.

Availability: Requires DNS access.

Example 1: Basic Usage

<?php

echo dns_check_record("example.com", "A") ? "Record present" : "No record found";

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.

Example 2: A Different Input

<?php

echo dns_check_record("example.com", "MX") ? "Mail records exist" : "No mail records";

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.

Practical Example: Applying It in a Program

<?php

foreach (["A", "AAAA", "MX"] as $recordType) { echo $recordType . ": " . (dns_check_record("example.com", $recordType) ? "yes" : "no") . PHP_EOL; }

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.

Important Behavior and Edge Cases

  • Key behavior: DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.
  • Environment: Requires DNS access.

Comparison With Related Functions

FunctionPurpose
dns_check_record()Checks for the presence of a DNS record; this is an alias of checkdnsrr().
checkdnsrr()dns_check_record() is an alias of checkdnsrr() and supports the same checks.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: DNS checks are network-dependent and presence of a record does not prove the host is safe or reachableDNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.

Key Takeaways

  • Checks for the presence of a DNS record; this is an alias of checkdnsrr().
  • DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.
  • Requires DNS access.

Summary: DNS checks are network-dependent and presence of a record does not prove the host is safe or reachable.

Share this resourceSend this page to someone who may find it useful.