PHPackages                             chielteuben/php-dns-extended - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chielteuben/php-dns-extended

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chielteuben/php-dns-extended
============================

Maintained fork of RemotelyLiving's PHP DNS library updated for compatibility and modern PHP support.

v5.1.0(1y ago)07MITPHPPHP &gt;=8.0

Since May 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/chielteuben/php-dns-extended)[ Packagist](https://packagist.org/packages/chielteuben/php-dns-extended)[ RSS](/packages/chielteuben-php-dns-extended/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (16)Versions (2)Used By (0)

[![License](https://camo.githubusercontent.com/dbdd256a59b3fd716fce0ad82e6c2e09f7e587ab2c9953553dd5140c5ded225f/68747470733a2f2f706f7365722e707567782e6f72672f636869656c74657562656e2f7068702d646e732d657874656e6465642f4c4943454e5345)](https://packagist.org/packages/chielteuben/php-dns-extended)

Fork Notes
==========

[](#fork-notes)

This is a fork of [remotelyliving/php-dns](https://github.com/remotelyliving/php-dns). The goal is to maintain and update dependencies for compatibility and modern PHP support. This package can be used as a drop-in replacement for the existing php-dns package with no breaking changes on the 5.x branch.

PHP-DNS: A DNS Abstraction in PHP
=================================

[](#php-dns-a-dns-abstraction-in-php)

### Use Cases

[](#use-cases)

This library might be for you if:

- You want to be able to query DNS records locally or over HTTPS
- You want observability into your DNS lookups
- You want something easy to test / mock in your implementation
- You want to try several different sources of DNS truth
- You want to easily extend it or contribute to get more behavior you want!

### Installation

[](#installation)

```
composer require chielteuben/php-dns
```

### Usage

[](#usage)

**Basic Resolvers** can be found in [src/Resolvers](https://github.com/chielteuben/php-dns-extended/tree/main/src/Resolvers)

These resolvers at the least implement the `Resolvers\Interfaces\DNSQuery` interface

- GoogleDNS (uses the GoogleDNS DNS over HTTPS API)
- CloudFlare (uses the CloudFlare DNS over HTTPS API)
- LocalSystem (uses the local PHP dns query function)
- Dig (Can use a specific nameserver per instance but requires the host OS to have dig installed). Based on [Spatie DNS](https://github.com/spatie/dns)

```
$resolver = new Resolvers\GoogleDNS();

// can query via convenience methods
$records = $resolver->getARecords('google.com'); // returns a collection of DNS A Records

// can also query by any RecordType.
$moreRecords = $resolver->getRecords($hostname, DNSRecordType::TYPE_AAAA);

// can query to see if any resolvers find a record or type.
$resolver->hasRecordType($hostname, $type) // true | false
$resolver->hasRecord($record) // true | false

// This becomes very powerful when used with the Chain Resolver
```

**Chain Resolver**

The Chain Resolver can be used to read through DNS Resolvers until an answer is found. Whichever you pass in first is the first Resolver it tries in the call sequence. It implements the same `DNSQuery` interface as the other resolvers but with an additional feature set found in the `Chain` interface.

So something like:

```
$chainResolver = new Chain($cloudFlareResolver, $googleDNSResolver, $localDNSResolver);
```

That will call the GoogleDNS Resolver first, if no answer is found it will continue on to the LocalSystem Resolver. The default call through strategy is First to Find aka `Resolvers\Interfaces\Chain::withFirstResults(): Chain`

You can randomly select which Resolver in the chain it tries first too via `Resolvers\Interfaces\Chain::randomly(): Chain`Example:

```
$foundRecord = $chainResolver->randomly()->getARecords('facebook.com')->pickFirst();
```

The above code calls through the resolvers randomly until it finds any non empty answer or has exhausted order the chain.

Lastly, and most expensively, there is `Resolvers\Interfaces\Chain::withAllResults(): Chain` and `Resolvers\Interfaces\Chain::withConsensusResults(): Chain`All results will be a merge from all the different sources, useful if you want to see what all is out there. Consensus results will be only the results in common from source to source.

[src/Resolvers/Interfaces](https://github.com/chielteuben/php-dns-extended/tree/main/src/Resolvers/Interfaces/Chain.php)

```
// returns the first non empty result set
$chainResolver->withFirstResults()->getARecords('facebook.com');

// returns the first non empty result set from a randomly selected resolver
$chainResolver->randomly()->getARecords('facebook.com');

// returns only common results between resolvers
$chainResolver->withConsensusResults()->getARecords('facebook.com');

// returns all collective responses with duplicates filtered out
$chainResolver->withAllResults()->getARecords('facebook.com');
```

**Cached Resolver**

If you use a PSR6 cache implementation, feel free to wrap whatever Resolver you want to use in the Cached Resolver. It will take in the the lowest TTL of the record(s) and use that as the cache TTL. You may override that behavior by setting a cache TTL in the constructor.

```
$cachedResolver = new Resolvers\Cached($cache, $resolverOfChoice);
$cachedResolver->getRecords('facebook.com'); // get from cache if possible or falls back to the wrapped resolver and caches the returned records
```

If you do not wish to cache empty result answers, you may call through with this additional option:

```
$cachedResolver->withEmptyResultCachingDisabled()->getARecords('facebook.com');
```

**Entities**

Take a look in the `src/Entities` to see what's available for you to query by and receive.

For records with extra type data, like SOA, TXT, MX, CNAME, and NS there is a data attribute on `Entities\DNSRecord` that will be set with the proper type.

**Reverse Lookup**

This is offered via a separate `ReverseDNSQuery` interface as it is not common or available for every type of DNS Resolver. Only the `LocalSystem` Resolver implements it.

### Observability

[](#observability)

All provided resolvers have the ability to add subscribers and listeners. They are directly compatible with `symfony/event-dispatcher`

All events can be found here: [src/Observability/Events](https://github.com/chielteuben/php-dns-extended/tree/main/src/Observability/Events)

With a good idea of what a subscriber can do with them here: [src/Observability/Subscribers](https://github.com/chielteuben/php-dns-extended/tree/main/src/Observability/Subscribers)

You could decide where you want to stream the events whether its to a log or somewhere else. The events are all safe to `json_encode()` without extra parsing.

If you want to see how easy it is to wire all this up, check out [the repl bootstrap](https://github.com/chielteuben/php-dns-extended/tree/main/bootstrap/repl.php)

### Logging

[](#logging)

All provided resolvers implement `Psr\Log\LoggerAwareInterface` and have a default `NullLogger` set at runtime.

### Tinkering

[](#tinkering)

Take a look in the [Makefile](https://github.com/chielteuben/php-dns-extended/blob/main/Makefile) for all the things you can do!

There is a very basic REPL implementation that wires up some Resolvers for you already and pipes events to sterr and stdout

`make repl`

```
christians-mbp:php-dns chthomas$ make repl
Psy Shell v0.9.9 (PHP 7.2.8 — cli) by Justin Hileman
>>> ls
Variables: $cachedResolver, $chainResolver, $cloudFlareResolver, $googleDNSResolver, $IOSubscriber, $localSystemResolver, $stdErr, $stdOut
>>> $records = $chainResolver->getARecords('facebook.com')
{
    "dns.query.profiled": {
        "elapsedSeconds": 0.21915197372436523,
        "transactionName": "CloudFlare:facebook.com.:A",
        "peakMemoryUsage": 9517288
    }
}
{
    "dns.queried": {
        "resolver": "CloudFlare",
        "hostname": "facebook.com.",
        "type": "A",
        "records": [
            {
                "hostname": "facebook.com.",
                "type": "A",
                "TTL": 224,
                "class": "IN",
                "IPAddress": "31.13.71.36"
            }
        ],
        "empty": false
    }
}
=> RemotelyLiving\PHPDNS\Entities\DNSRecordCollection {#2370}
>>> $records->pickFirst()->toArray()
=> [
     "hostname" => "facebook.com.",
     "type" => "A",
     "TTL" => 224,
     "class" => "IN",
     "IPAddress" => "31.13.71.36",
   ]
>>> $records = $chainResolver->withConsensusResults()->getRecords('facebook.com', 'TXT')
{
    "dns.query.profiled": {
        "elapsedSeconds": 0.023031949996948242,
        "transactionName": "CloudFlare:facebook.com.:TXT",
        "peakMemoryUsage": 9615080
    }
}
{
    "dns.queried": {
        "resolver": "CloudFlare",
        "hostname": "facebook.com.",
        "type": "TXT",
        "records": [
            {
                "hostname": "facebook.com.",
                "type": "TXT",
                "TTL": 9136,
                "class": "IN",
                "data": "v=spf1 redirect=_spf.facebook.com"
            }
        ],
        "empty": false
    }
}
{
    "dns.query.profiled": {
        "elapsedSeconds": 0.23299598693847656,
        "transactionName": "GoogleDNS:facebook.com.:TXT",
        "peakMemoryUsage": 9615080
    }
}
{
    "dns.queried": {
        "resolver": "GoogleDNS",
        "hostname": "facebook.com.",
        "type": "TXT",
        "records": [
            {
                "hostname": "facebook.com.",
                "type": "TXT",
                "TTL": 21121,
                "class": "IN",
                "data": "v=spf1 redirect=_spf.facebook.com"
            }
        ],
        "empty": false
    }
}
{
    "dns.query.profiled": {
        "elapsedSeconds": 0.0018258094787597656,
        "transactionName": "LocalSystem:facebook.com.:TXT",
        "peakMemoryUsage": 9615080
    }
}
{
    "dns.queried": {
        "resolver": "LocalSystem",
        "hostname": "facebook.com.",
        "type": "TXT",
        "records": [
            {
                "hostname": "facebook.com.",
                "type": "TXT",
                "TTL": 25982,
                "class": "IN",
                "data": "v=spf1 redirect=_spf.facebook.com"
            }
        ],
        "empty": false
    }
}
=> RemotelyLiving\PHPDNS\Entities\DNSRecordCollection {#2413}
>>> $records->pickFirst()->getData()->getValue()
=> "v=spf1 redirect=_spf.facebook.com"
>>>
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance46

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

409d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/946625?v=4)[Chiel Teuben](/maintainers/chielteuben)[@chielteuben](https://github.com/chielteuben)

---

Top Contributors

[![remotelyliving](https://avatars.githubusercontent.com/u/2728347?v=4)](https://github.com/remotelyliving "remotelyliving (4 commits)")[![chielteuben](https://avatars.githubusercontent.com/u/946625?v=4)](https://github.com/chielteuben "chielteuben (3 commits)")[![chiel-n4all](https://avatars.githubusercontent.com/u/229992797?v=4)](https://github.com/chiel-n4all "chiel-n4all (3 commits)")[![lynnverse](https://avatars.githubusercontent.com/u/96229909?v=4)](https://github.com/lynnverse "lynnverse (3 commits)")[![stephanvierkant](https://avatars.githubusercontent.com/u/601833?v=4)](https://github.com/stephanvierkant "stephanvierkant (3 commits)")[![joeh](https://avatars.githubusercontent.com/u/35780787?v=4)](https://github.com/joeh "joeh (1 commits)")[![masroore](https://avatars.githubusercontent.com/u/200963?v=4)](https://github.com/masroore "masroore (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chielteuben-php-dns-extended/health.svg)

```
[![Health](https://phpackages.com/badges/chielteuben-php-dns-extended/health.svg)](https://phpackages.com/packages/chielteuben-php-dns-extended)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M577](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
