From 5307cfe48ad75949381d8b49d79bacf892444286 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sat, 13 Jun 2015 19:56:26 +0000 Subject: [PATCH] functions.inc.php check_domain(): Measure time needed for the nameserver queries, and error_log a warning if the queries need more than 2 seconds in total. Inspired by a question from t-ask on IRC, who suffered from a slow nameserver and had some "fun" to debug it ;-) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1790 a1433add-5e2c-0410-b055-b7f2511e0802 --- functions.inc.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index b15e3f53..a255dbbe 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -207,18 +207,31 @@ function check_domain ($domain) { // Look for an AAAA, A, or MX record for the domain if(function_exists('checkdnsrr')) { + $start = microtime(true); # check for slow nameservers, part 1 + // AAAA (IPv6) is only available in PHP v. >= 5 - if (version_compare(phpversion(), "5.0.0", ">=")) { - if (checkdnsrr($domain,'AAAA')) return ''; + if (version_compare(phpversion(), "5.0.0", ">=") && checkdnsrr($domain,'AAAA')) { + $retval = ''; + } elseif (checkdnsrr($domain,'A')) { + $retval = ''; + } elseif (checkdnsrr($domain,'MX')) { + $retval = ''; + } else { + $retval = sprintf(Config::lang('pInvalidDomainDNS'), htmlentities($domain)); + } + + $end = microtime(true); # check for slow nameservers, part 2 + $time_needed = $end - $start; + if ($time_needed > 2) { + error_log("Warning: slow nameserver - lookup for $domain took $time_needed seconds"); } - if (checkdnsrr($domain,'A')) return ''; - if (checkdnsrr($domain,'MX')) return ''; - return sprintf(Config::lang('pInvalidDomainDNS'), htmlentities($domain)); + + return $retval; } else { return 'emailcheck_resolve_domain is enabled, but function (checkdnsrr) missing!'; } } - + return ''; }