diff --git a/examples/_bootstrap.php b/examples/_bootstrap.php new file mode 100644 index 0000000..d662063 --- /dev/null +++ b/examples/_bootstrap.php @@ -0,0 +1,20 @@ +getType()), $record->getValue(), $record->getTtl()); + } +} + +function pretty_print_error(string $queryName, \Throwable $error) { + print "-- " . $queryName . " " . str_repeat("-", 70 - strlen($queryName)) . "\r\n"; + print get_class($error) . ": " . $error->getMessage() . "\r\n"; +} diff --git a/examples/benchmark.php b/examples/benchmark.php index b08c2c8..717f163 100644 --- a/examples/benchmark.php +++ b/examples/benchmark.php @@ -1,6 +1,6 @@ getValue(); - }, $records); - - print implode(", ", $records); + pretty_print_records($domain, yield Dns\resolve($domain)); } catch (Dns\ResolutionException $e) { - print get_class($e); + pretty_print_error($domain, $e); } $time = round(microtime(1) - $start, 2); $timings[] = $time; - print " in " . $time . " ms" . PHP_EOL; + printf("%'-74s\r\n\r\n", " in " . $time . " ms"); } - print PHP_EOL; - print (array_sum($timings) / count($timings)) . " ms for an average query." . PHP_EOL; + $averageTime = array_sum($timings) / count($timings); + + print "{$averageTime} ms for an average query." . PHP_EOL; }); diff --git a/examples/custom-config.php b/examples/custom-config.php index 4337e82..166d4da 100644 --- a/examples/custom-config.php +++ b/examples/custom-config.php @@ -1,6 +1,6 @@ pendingQueries[$type . " " . $name])) { - return $this->pendingQueries[$type . " " . $name]; + $pendingQueryKey = $type . " " . $name; + + if (isset($this->pendingQueries[$pendingQueryKey])) { + return $this->pendingQueries[$pendingQueryKey]; } $promise = call(function () use ($name, $type) {