1
0
mirror of https://github.com/danog/dns.git synced 2025-01-22 21:41:11 +01:00

Add simple examples that queries 10 out of the top 500 domains

This commit is contained in:
Niklas Keller 2017-06-24 01:51:41 +02:00
parent ad55bcf870
commit 5f73365b9b

23
examples/benchmark.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require __DIR__ . "/../vendor/autoload.php";
use Amp\Dns;
use Amp\Loop;
$domains = file_get_contents("https://moz.com/top500/domains/csv");
$domains = array_map(function ($line) {
return trim(explode(",", $line)[1], '"/');
}, array_filter(explode("\n", $domains)));
Loop::run(function () use ($domains) {
for ($i = 0; $i < 10; $i++) {
$domain = $domains[mt_rand(0, count($domains) - 1)];
try {
yield Dns\resolve($domain);
} catch (Dns\ResolutionException $e) {
print $domain . ": " . get_class($e) . PHP_EOL;
}
}
});