From e61c189bcc30703a4ea3b4c894ee112b34f00add Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 8 Mar 2016 19:09:38 +0000 Subject: [PATCH] Vastly improve checking for domain in gravity.list (think 30+ seconds down to 1) --- data.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/data.php b/data.php index 3802707f3..4fac0ad9e 100644 --- a/data.php +++ b/data.php @@ -123,21 +123,26 @@ function getAllQueries() { $dns_queries = getDnsQueries($log); $fileName = '/etc/pihole/gravity.list'; - $file = file_get_contents($fileName); - + //Turn gravity.list into an array + $lines = explode("\n", file_get_contents($fileName)); + + //Create a new array and set domain name as index instead of value, with value as 1 + foreach(array_values($lines) as $v){ + $new_lines[trim(strstr($v, ' '))] = 1; + } + foreach ($dns_queries as $query) { $time = date_create(substr($query, 0, 16)); $exploded = explode(" ", trim($query)); - - $searchString = " {$exploded[6]}\n"; - - if (strpos($file,$searchString)) { - $extra="Pi-holed"; - } - else { - $extra="OK"; - }; + //Is index of the domain name set? + if (isset($new_lines[$exploded[6]])){ + $extra = "Pi-holed"; + } + else + { + $extra = "OK"; + } array_push($allQueries['data'], array( $time->format('Y-m-d\TH:i:s'), substr($exploded[5], 6, -1),