From 6e9d02a8cee18255449a28ee92fa5ed0e13e659f Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Sun, 10 Jan 2010 14:48:00 +0000 Subject: [PATCH] cache astext to reduce number of dns queries git-svn-id: http://www.observium.org/svn/observer/trunk@654 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/functions.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 800f81851..78a3b5a4d 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -733,7 +733,7 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig function get_astext($asn) { - global $config; + global $config,$cache; if (isset($config['astext'][$asn])) { @@ -741,9 +741,17 @@ function get_astext($asn) } else { - $result = dns_get_record("AS$asn.asn.cymru.com",DNS_TXT); - $txt = explode('|',$result[0]['txt']); - return trim(str_replace('"', '', $txt[4])); + if (isset($cache['astext'][$asn])) + { + return $cache['astext'][$asn]; + } + else + { + $result = dns_get_record("AS$asn.asn.cymru.com",DNS_TXT); + $txt = explode('|',$result[0]['txt']); + $cache['astext'][$asn] = $txt[4]; + return trim(str_replace('"', '', $txt[4])); + } } }