{"id":29111904,"url":"https://github.com/utopia-php/dns","last_synced_at":"2026-05-20T06:13:01.156Z","repository":{"id":273144562,"uuid":"439784558","full_name":"utopia-php/dns","owner":"utopia-php","description":"Lite \u0026 fast micro PHP DNS server abstraction that is **easy to use**.","archived":false,"fork":false,"pushed_at":"2025-06-29T07:56:00.000Z","size":154,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-29T08:29:43.899Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/utopia-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-12-19T05:37:10.000Z","updated_at":"2025-06-05T07:18:26.000Z","dependencies_parsed_at":"2025-05-08T04:24:47.659Z","dependency_job_id":"6c6f521c-3d00-4d2c-8c46-ff404a9c4624","html_url":"https://github.com/utopia-php/dns","commit_stats":null,"previous_names":["utopia-php/dns"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/utopia-php/dns","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utopia-php","download_url":"https://codeload.github.com/utopia-php/dns/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdns/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262565693,"owners_count":23329653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-29T10:02:19.548Z","updated_at":"2026-05-20T06:13:01.147Z","avatar_url":"https://github.com/utopia-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utopia DNS\n\n[![Tests](https://github.com/utopia-php/dns/actions/workflows/tests.yml/badge.svg)](https://github.com/utopia-php/dns/actions/workflows/tests.yml)\n[![Packagist Version](https://img.shields.io/packagist/v/utopia-php/dns.svg)](https://packagist.org/packages/utopia-php/dns)\n![Packagist Downloads](https://img.shields.io/packagist/dt/utopia-php/dns.svg)\n[![Discord](https://img.shields.io/discord/564160730845151244)](https://appwrite.io/discord)\n\nUtopia 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.\n\nAlthough part of the [Utopia Framework](https://github.com/utopia-php/framework) family, the library is framework-agnostic and can be used in any PHP project.\n\n## Installation\n\n```bash\ncomposer require utopia-php/dns\n```\n\nThe library requires PHP 8.3+ with the `ext-sockets` extension. The Swoole adapter additionally needs the `ext-swoole` extension.\n\n## Quick start\n\nCreate an authoritative DNS server by wiring an adapter (UDP socket implementation) and a resolver (how records are answered). The example below uses the native PHP socket adapter and the in-memory zone resolver.\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Utopia\\DNS\\Adapter\\Native;\nuse Utopia\\DNS\\Message\\Record;\nuse Utopia\\DNS\\Resolver\\Memory;\nuse Utopia\\DNS\\Server;\nuse Utopia\\DNS\\Zone;\n\n$adapter = new Native('0.0.0.0', 5300);\n\n$zone = new Zone(\n    name: 'example.test',\n    records: [\n        new Record(name: 'example.test', type: Record::TYPE_A, rdata: '192.0.2.1', ttl: 60),\n        new Record(name: 'www.example.test', type: Record::TYPE_CNAME, rdata: 'example.test', ttl: 60),\n        new Record(\n            name: 'example.test',\n            type: Record::TYPE_SOA,\n            rdata: 'ns1.example.test hostmaster.example.test 1 7200 1800 1209600 3600',\n            ttl: 60\n        ),\n    ]\n);\n\n$server = new Server($adapter, new Memory($zone));\n$server-\u003esetDebug(true);\n\n$server-\u003estart();\n```\n\nThe server listens on both UDP and TCP port `5300` (RFC 5966) and answers queries for `example.test` from the in-memory zone. Implement the [`Utopia\\DNS\\Resolver`](src/DNS/Resolver.php) interface to serve records from databases, APIs, or other stores.\n\n## Resolvers\n- `Memory`: authoritative resolver backed by a `Zone` object\n- `Proxy`: forwards queries to another DNS server\n- `Cloudflare`: proxy resolver preconfigured for `1.1.1.1` / `1.0.0.1`\n- `Google`: proxy resolver preconfigured for `8.8.8.8` / `8.8.4.4`\n\nResolvers 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.\n\n## Adapters\n- `Native`: pure PHP UDP server based on `ext-sockets`\n- `Swoole`: non-blocking server built on the Swoole UDP runtime\n\nAdapters 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.\n\n## DNS client\n\nThe bundled client can query any DNS server and returns fully decoded messages.\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Utopia\\DNS\\Client;\nuse Utopia\\DNS\\Message;\nuse Utopia\\DNS\\Message\\Question;\nuse Utopia\\DNS\\Message\\Record;\n\n$client = new Client('1.1.1.1');\n\n$query = Message::query(\n    new Question('example.com', Record::TYPE_A)\n);\n\n$response = $client-\u003equery($query);\n\nforeach ($response-\u003eanswers as $answer) {\n    echo \"{$answer-\u003ename} {$answer-\u003ettl} {$answer-\u003egetTypeName()} {$answer-\u003erdata}\\n\";\n}\n```\n\n## Telemetry\n\n`Server::setTelemetry()` accepts any adapter from [`utopia-php/telemetry`](https://github.com/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.\n\n## Development\n- Install dependencies: `composer install`\n- Static analysis: `composer check`\n- Coding standards: `composer lint` (use `composer format` to auto-fix)\n- Tests: `composer test`\n- Sample Swoole server for manual testing: `docker compose up`\n\n## Benchmarking\n\nRun the bundled benchmark tool to measure throughput against your server:\n\n```bash\nphp tests/benchmark.php --server=127.0.0.1 --port=5300 --iterations=1000 --concurrency=20\n```\n\nThe script reports requests per second, latency distribution, and error counts across common record types.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futopia-php%2Fdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fdns/lists"}