orlo / dns-hostname-expansion
may perform dns lookup + expansion of hosts
1.0
2024-12-04 13:03 UTC
Requires
- php: ^8.2
Requires (Dev)
- php-parallel-lint/php-parallel-lint: ^1.4
- phpunit/phpunit: ^11
- psalm/phar: ^5.26
README
ElasticSearch (for example) needs a list of hosts to talk to, for instance :
This allows you to have a single DNS record (e.g. in Route53) which responds with multiple A records, which then get formatted into an appropriate list, e.g
- DNS record: elasticsearch.test.org resolves to 1.2.3.4, 1.2.3.5, 1.2.4.6
- Becomes: https://1.2.3.4:9200, https://1.2.3.5:9200, https://1.2.3.6:9200
The prefix + suffix used in decoration are configurable and could be omitted.
In the event DNS lookup fails, we fall back to returning the passed in host - e.g. https://elasticsearch.test.org:9200
Usage
- composer require orlo/dns-hostname-expansion
- ...
<?php require_once(__DIR__ . '/vendor/autoload.php'); $hosts = \Orlo\DnsHostnameExpansion\DNSLookup::expandFromDnsALookup("my.host.name", "https://", "9200); // e.g. ["https://1.2.3.4:9200","https://1.2.3.5:9200"]