PHPackages                             sirmonti/doh - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. sirmonti/doh

ActiveLibrary[HTTP &amp; Networking](/categories/http)

sirmonti/doh
============

DNS over HTTPS client library

3.0.0(2y ago)034MITPHPPHP &gt;=7.4

Since May 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sirmonti/DOH)[ Packagist](https://packagist.org/packages/sirmonti/doh)[ Docs](https://github.com/sirmonti/DOH)[ RSS](/packages/sirmonti-doh/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)DependenciesVersions (7)Used By (0)

DOH - DNS over HTTPS client library for PHP
===========================================

[](#doh---dns-over-https-client-library-for-php)

[![Version](https://camo.githubusercontent.com/d8bcca45dffeb8d55a204b28c37a90a58d1323e0d5d58541180dbf5e806c54c3/68747470733a2f2f706f7365722e707567782e6f72672f7369726d6f6e74692f646f682f76657273696f6e)](//packagist.org/packages/sirmonti/doh)[![License](https://camo.githubusercontent.com/f0eaecde81a19657197f8ce613c227af39d78787f78692964db6e69cd138a2e1/68747470733a2f2f706f7365722e707567782e6f72672f7369726d6f6e74692f646f682f6c6963656e7365)](//packagist.org/packages/sirmonti/doh)

Introduction
------------

[](#introduction)

DNS resolve is a well known function that is implemented in all operating systems, then, Why we need a different way to do it? The main reason is privacy, standard DNS protocol don't encrypt connections, which means DNS requests can be spied and forged.

But there are other reasons; first, DOH is fast, more fast than a lot of local servers. This is not very surprisingly if you consider that cloudflare and google (the main DOH providers) have huge network infraestructures. But there are more, DOH provides a more descriptive errors. For example, standard DNS servers can misinterpret network errors as nonexistent records. DOH will correctly report the error.

If you need a fast and reliable DNS name resolution, If you need fast and reliable name resolution, more precisely, if you need bulk name resolution, DOH provides a better solution than standard DNS servers.

Complete documentation can be found in the [github.io page](https://sirmonti.github.io/DOH/)

Install
-------

[](#install)

Vía composer

```
composer require sirmonti/doh
```

Usage
-----

[](#usage)

Actually, the library supports two DoH providers, cloudflare and google. The support is implemented across two wrapper classes:

- DOHGG: Resolves names via google
- DOHCF: Resolves names via cloudflare

There isn't any differente to use one class or another. The only reason to prefer one or the other is the sympathy you have for the company.

The classes are called statically, there is no need to create an object. For example, if you want to get the IP address for [www.google.com](http://www.google.com) using google backend, the call will be:

```
$ipaddresses=DOHGG::dns('www.google.com','A');
```

If you have more sympathy for cloudflare, you can use it as a backend

```
$ipaddresses=DOHCF::dns('www.google.com','A');
```

The classes have the following methods:

functionDescriptionIPtoDNS($ip)Convert an IP address to a DNS encoding valid for PTR querysdns($name,$type)Resolve a DNS query. $name is the name to resolve and $type is the record type searchedgetStatus()Get the status code for the last queryDNS resolution
--------------

[](#dns-resolution)

The method "dns($name,$type)" execute a DNS query. The query return an array with the responses. In case of error the function returns an empty array and set "status" attribute with the error code. The parameters are the name we want resolve and the record type we are asking for.

When parameters have an invalid value, an InvalidValurException will be fired, network or DNS error doesn't fire any exception, error will be reported with an status code.

Valid record types: NS, MX, TXT, A, AAAA, CNAME, SPF, SOA, PTR, SRV, DS, DNSKEY

The response is an array with the returned responses. If the query don't have a valid response or an error ocurrs, the call will return an empty array and set the "status" property to the error code. If all is ok, the status code will be zero.

status code values:

- 0: OK
- 1: Empty response. There are not response to this query.
- 2: The DNS servers for this domain are misconfigured
- 3: The domain does not exist
- 4: Network error
- 5: Lame response
- 100: Invalid record type provided
- 101: Invalid IP address provided
- 10XX: Values above 1000 contains error code returned by DNS server

On invalid parameters an InvalidArgumentException will be fired with the status codes 100 or 101.

Examples
--------

[](#examples)

```
$resp = DOHCF::dns('www.google.com','A'); // Query cloudflare with a single response
echo "\nResponse A query:\n";
print_r($resp);
printf("DNS response status code: %d\n",DOHCF::getStatus());
```

The script produces this response

```
Response to A query:
Array
(
    [0] => 142.250.200.68
)
DNS response status code: 0

```

In this example, we use the DOH\_PROVIDER constant to set the resolver

```
$resp = DOHGG:dns('google.com','TXT'); // Query with a multiple response
echo "\nResponse TXT query:\n";
print_r($resp);
printf("DNS response status code: %d\n",DOHGG::getStatus());
```

The script produces this response

```
Response to TXT query:
Array
(
    [0] => "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95"
    [1] => "MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB"
    [2] => "v=spf1 include:_spf.google.com ~all"
    [3] => "docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"
    [4] => "apple-domain-verification=30afIBcvSuDV2PLX"
    [5] => "google-site-verification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB-0Hf5o"
    [6] => "google-site-verification=TV9-DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ"
    [7] => "docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"
    [8] => "globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="
)
DNS response status code: 0

```

Example for a bogus query. We use the hardcoded default resolver

```
$resp = DOHCF::dns('nonexistentdomain.test','TXT'); // Query with an invalid response
echo "\nResponse TXT query:\n";
print_r($resp);
printf("DNS response status code: %d\n",DOHCF::getStatus());
```

The script produces this response

```
Response to bogus query:

Array
(
)
DNS response status code: 3

```

LICENSE
-------

[](#license)

This library is licensed under [MIT LICENSE](LICENSE)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~248 days

Total

5

Last Release

845d ago

Major Versions

1.0.0 → 2.0.02024-01-15

2.5.0 → 3.0.02024-01-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e6e5c1adbb57005dac92a328cebad6681217e99be229a35a24c500cf54f3dac?d=identicon)[sirmonti](/maintainers/sirmonti)

---

Top Contributors

[![sirmonti](https://avatars.githubusercontent.com/u/17907659?v=4)](https://github.com/sirmonti "sirmonti (8 commits)")

---

Tags

dnsresolverdohdnsoverhttps

### Embed Badge

![Health badge](/badges/sirmonti-doh/health.svg)

```
[![Health](https://phpackages.com/badges/sirmonti-doh/health.svg)](https://phpackages.com/packages/sirmonti-doh)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[illuminate/http

The Illuminate Http package.

11936.0M5.1k](/packages/illuminate-http)[mikepultz/netdns2

PHP DNS Resolver and Updater Library

1292.1k5](/packages/mikepultz-netdns2)[danog/dns-over-https

Async DNS-over-HTTPS resolution for Amp.

11709.8k7](/packages/danog-dns-over-https)

PHPackages © 2026

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