2017-06-24 01:51:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . "/../vendor/autoload.php";
|
|
|
|
|
|
|
|
use Amp\Dns;
|
|
|
|
use Amp\Loop;
|
|
|
|
|
2017-09-09 19:40:48 +02:00
|
|
|
print "Downloading top 500 domains..." . PHP_EOL;
|
|
|
|
|
2017-06-24 01:51:41 +02:00
|
|
|
$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) {
|
2017-09-09 19:40:48 +02:00
|
|
|
print "Starting sequential queries..." . PHP_EOL;
|
|
|
|
|
|
|
|
$timings = [];
|
|
|
|
|
2017-06-24 01:51:41 +02:00
|
|
|
for ($i = 0; $i < 10; $i++) {
|
2017-09-09 19:40:48 +02:00
|
|
|
$start = microtime(1);
|
2017-06-24 01:51:41 +02:00
|
|
|
$domain = $domains[mt_rand(0, count($domains) - 1)];
|
|
|
|
|
2017-09-09 19:40:48 +02:00
|
|
|
print $domain . ": ";
|
|
|
|
|
2017-06-24 01:51:41 +02:00
|
|
|
try {
|
2017-09-09 19:40:48 +02:00
|
|
|
$records = yield Dns\resolve($domain);
|
|
|
|
$records = array_map(function ($record) {
|
|
|
|
return $record->getValue();
|
|
|
|
}, $records);
|
|
|
|
|
|
|
|
print implode(", ", $records);
|
2017-06-24 01:51:41 +02:00
|
|
|
} catch (Dns\ResolutionException $e) {
|
2017-09-09 19:40:48 +02:00
|
|
|
print get_class($e);
|
2017-06-24 01:51:41 +02:00
|
|
|
}
|
2017-09-09 19:40:48 +02:00
|
|
|
|
|
|
|
$time = round(microtime(1) - $start, 2);
|
|
|
|
$timings[] = $time;
|
|
|
|
|
|
|
|
print " in " . $time . " ms" . PHP_EOL;
|
2017-06-24 01:51:41 +02:00
|
|
|
}
|
2017-09-09 19:40:48 +02:00
|
|
|
|
|
|
|
print PHP_EOL;
|
|
|
|
print (array_sum($timings) / count($timings)) . " ms for an average query." . PHP_EOL;
|
2017-06-24 01:51:41 +02:00
|
|
|
});
|