Download the PHP package utopia-php/dns without Composer
On this page you can find all versions of the php package utopia-php/dns. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dns
Utopia DNS
[!IMPORTANT] This repository is a read-only mirror of the utopia-php monorepo. Development happens in
packages/dns— please open issues and pull requests there.
Utopia DNS is a modern PHP 8.3 toolkit for building DNS servers and clients. It provides a fully-typed DNS message encoder/decoder, pluggable resolvers, and telemetry hooks so you can stand up custom authoritative or proxy DNS services with minimal effort.
Although part of the Utopia Framework family, the library is framework-agnostic and can be used in any PHP project.
Installation
The library requires PHP 8.5+ with the ext-sockets extension. The Swoole adapter additionally needs the ext-swoole extension.
Quick start
Create an authoritative DNS server by wiring an adapter (which transports to listen on) and a resolver (how records are answered). The example below uses the native PHP socket adapter with UDP and TCP transports and the in-memory zone resolver.
The server listens on UDP and TCP port 5300 (RFC 5966) and answers queries for example.test from the in-memory zone. Implement the Utopia\DNS\Resolver interface to serve records from databases, APIs, or other stores.
Resolvers
Memory: authoritative resolver backed by aZoneobjectProxy: forwards queries to another DNS serverCloudflare: proxy resolver preconfigured for1.1.1.1/1.0.0.1Google: proxy resolver preconfigured for8.8.8.8/8.8.4.4
Resolvers can be combined with any adapter. Implementing the Resolver interface allows you to plug in custom logic while reusing the message encoding/decoding and telemetry tooling.
Resolvers receive a Query, which carries the decoded Message plus its source: the client IP, port, and transport protocol. Cross-cutting concerns such as tracing or rate limiting compose as resolver decorators:
Note that UDP source addresses can be forged; stream transports (Protocol::Tcp, Protocol::Https) carry verified peer addresses.
Adapters and transports
An adapter composes one or more transports into a single process. Transports are responsible only for receiving and returning raw packets — they call back into the server with the payload, source IP, and port so your resolver logic stays isolated.
Native: blocking select loop based onext-sockets, withNative\UdpandNative\TcptransportsSwoole: non-blocking server built on the Swoole runtime, withSwoole\Udp,Swoole\Tcp, andSwoole\Httptransports
Transports of one adapter share the process and (for Swoole) the worker pool. UDP and TCP transports can bind the same port number; each HTTP transport needs its own TCP port:
Swoole\Http implements DNS over HTTPS (RFC 8484): it accepts wire-format queries via GET (?dns= base64url) and POST (application/dns-message). Leave certPath unset to serve plain HTTP behind a TLS-terminating proxy.
Client addresses behind load balancers
Load balancers usually replace the client address with their own. The TCP transports accept a PROXY protocol v1/v2 header (as sent by DigitalOcean, AWS, or HAProxy load balancers) when constructed with proxyProtocol: true, and report the original client address to your resolver:
Only enable this behind a load balancer that sends the header — with it enabled, direct DNS clients are rejected. The HTTP transport uses new Swoole\Http('0.0.0.0', 443, trustProxy: true) instead, which reads the X-Forwarded-For header. PROXY protocol is a TCP feature: UDP transports always see the packet source address, so preserve it at the network layer (for example externalTrafficPolicy: Local on Kubernetes).
DNS client
The bundled client can query any DNS server and returns fully decoded messages.
Telemetry
Server::setTelemetry() accepts any adapter from utopia-php/telemetry. Counters (dns.queries.total, dns.responses.total) and a histogram (dns.query.duration) are emitted automatically, enabling Prometheus or OpenTelemetry pipelines with minimal configuration.
Development
- Install dependencies:
composer install - Static analysis:
composer check - Coding standards:
composer lint(usecomposer formatto auto-fix) - Tests:
composer test - Sample Swoole server for manual testing:
docker compose up
Benchmarking
Run composer bench to start a sample Swoole server and measure UDP, TCP, and DNS over HTTPS throughput against it with dnspyre (fetched automatically when not installed; tune with the PORT, QUERIES, CONCURRENCY, and DOMAINS environment variables). To benchmark an already-running server directly:
The report covers requests per second, success counts, and latency percentiles per transport.
Upgrading from 1.x
Version 2.0 replaces per-adapter protocol flags with composable transports:
new Native($host, $port)→new Native([new Native\Udp($host, $port), new Native\Tcp($host, $port)])new Swoole($host, $port, $numWorkers)→new Swoole([new Swoole\Udp($host, $port), new Swoole\Tcp($host, $port)], workers: $numWorkers)enableTcp: false→ omit theTcptransport- TCP tuning options (
maxTcpClients,maxTcpBufferSize,maxTcpFrameSize,tcpIdleTimeout) moved to theNative\Tcpconstructor asmaxClients,maxBufferSize,maxFrameSize, andidleTimeout Resolver::resolve()now receives aUtopia\DNS\Querycarrying the decoded message and its source ($query->message,$query->ip,$query->port,$query->protocol) instead of a bareMessageAdapter::getName()andResolver::getName()were removed without replacement- The server no longer emits
utopia-php/spantraces (dns.packet); metrics viaServer::setTelemetry()are unchanged. Emit spans from yourResolverimplementation if you need tracing
License
MIT
All versions of dns with dependencies
ext-sockets Version *
utopia-php/telemetry Version ^0.4
utopia-php/validators Version ^0.6
utopia-php/domains Version ^4.0.0