From 4c97933d5a32bc97142e965e5e3f6f8828d36cba Mon Sep 17 00:00:00 2001 From: CT2JAY Date: Tue, 28 Feb 2017 00:03:41 +0000 Subject: [PATCH 1/3] Speedup functions with grep and egrep --- include/functions.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/include/functions.php b/include/functions.php index 3cfcddd..af11989 100644 --- a/include/functions.php +++ b/include/functions.php @@ -24,7 +24,7 @@ function getMMDVMHostFileVersion() { function getFirmwareVersion() { $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; - $logLines = explode("\n", `grep "MMDVM protocol version" $logPath`); + $logLines = explode("\n", `LC_ALL=C egrep "MMDVM protocol version" $logPath`); $firmware = "n/a"; if (count($logLines) >= 2) { $firmware = substr($logLines[count($logLines)-2], strpos($logLines[count($logLines)-2], "description")+13, strlen($logLines[count($logLines)-2])-strpos($logLines[count($logLines)-2], "description")+13); @@ -72,7 +72,7 @@ function getDMRNetwork2() { function getDMRMasterState() { $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; - $logLines = explode("\n", `egrep -h "(DMR, Logged into the master successfully)|(DMR, Closing DMR Network)" $logPath`); + $logLines = explode("\n", `LC_ALL=C egrep -h "(DMR, Logged into the master successfully)|(DMR, Closing DMR Network)" $logPath`); $state = -1; foreach($logLines as $logLine) { if (strpos($logLine, "successfully") > 0) { @@ -189,14 +189,14 @@ function getMMDVMLog() { // Open Logfile and copy loglines into LogLines-Array() $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; //$logLines = explode("\n", `grep M: $logPath`); - $logLines = explode("\n", `egrep -h "from|end|watchdog|lost" $logPath`); + $logLines = explode("\n", `LC_ALL=C egrep -h "from|end|watchdog|lost" $logPath`); return $logLines; } function getShortMMDVMLog() { // Open Logfile and copy loglines into LogLines-Array() $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; - $logLines = explode("\n", `egrep -h "from|end|watchdog|lost|Alias|0000" $logPath | tail -20`); + $logLines = explode("\n", `LC_ALL=C egrep -h "from|end|watchdog|lost|Alias|0000" $logPath | tail -20`); return $logLines; } @@ -204,7 +204,7 @@ function getYSFGatewayLog() { // Open Logfile and copy loglines into LogLines-Array() $logPath = YSFGATEWAYLOGPATH."/".YSFGATEWAYLOGPREFIX."-".date("Y-m-d").".log"; //$logLines = explode("\n", `egrep -h "D:|M:" $logPath`); - $logLines = explode("\n", `egrep -h "Starting|DISCONNECT|Connect|Automatic" $logPath`); + $logLines = explode("\n", `LC_ALL=C egrep -h "Starting|DISCONNECT|Connect|Automatic" $logPath`); return $logLines; } @@ -787,10 +787,12 @@ function getName($callsign) { $callsign = substr($callsign,0,strpos($callsign,"-")); } $delimiter =" "; - exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); - if (count($output) == 0) { +// exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); + exec("LC_ALL=C egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); + if (count($output) == 0) { $delimiter = "\t"; - exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); +// exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); + exec("LC_ALL=C egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); } if (count($output) !== 0) { $name = substr($output[0], strpos($output[0],$delimiter)+1); From bc973f20a665c2f5ea538363365c65df5dc8e3be Mon Sep 17 00:00:00 2001 From: CT2JAY Date: Tue, 28 Feb 2017 00:30:34 +0000 Subject: [PATCH 2/3] Speedup functions with grep and egrep --- include/functions.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/functions.php b/include/functions.php index af11989..919ef16 100644 --- a/include/functions.php +++ b/include/functions.php @@ -24,7 +24,7 @@ function getMMDVMHostFileVersion() { function getFirmwareVersion() { $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; - $logLines = explode("\n", `LC_ALL=C egrep "MMDVM protocol version" $logPath`); + $logLines = explode("\n", `egrep "MMDVM protocol version" $logPath`); $firmware = "n/a"; if (count($logLines) >= 2) { $firmware = substr($logLines[count($logLines)-2], strpos($logLines[count($logLines)-2], "description")+13, strlen($logLines[count($logLines)-2])-strpos($logLines[count($logLines)-2], "description")+13); @@ -72,7 +72,7 @@ function getDMRNetwork2() { function getDMRMasterState() { $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; - $logLines = explode("\n", `LC_ALL=C egrep -h "(DMR, Logged into the master successfully)|(DMR, Closing DMR Network)" $logPath`); + $logLines = explode("\n", `egrep -h "(DMR, Logged into the master successfully)|(DMR, Closing DMR Network)" $logPath`); $state = -1; foreach($logLines as $logLine) { if (strpos($logLine, "successfully") > 0) { @@ -189,14 +189,14 @@ function getMMDVMLog() { // Open Logfile and copy loglines into LogLines-Array() $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; //$logLines = explode("\n", `grep M: $logPath`); - $logLines = explode("\n", `LC_ALL=C egrep -h "from|end|watchdog|lost" $logPath`); + $logLines = explode("\n", `egrep -h "from|end|watchdog|lost" $logPath`); return $logLines; } function getShortMMDVMLog() { // Open Logfile and copy loglines into LogLines-Array() $logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log"; - $logLines = explode("\n", `LC_ALL=C egrep -h "from|end|watchdog|lost|Alias|0000" $logPath | tail -20`); + $logLines = explode("\n", `egrep -h "from|end|watchdog|lost|Alias|0000" $logPath | tail -20`); return $logLines; } @@ -204,7 +204,7 @@ function getYSFGatewayLog() { // Open Logfile and copy loglines into LogLines-Array() $logPath = YSFGATEWAYLOGPATH."/".YSFGATEWAYLOGPREFIX."-".date("Y-m-d").".log"; //$logLines = explode("\n", `egrep -h "D:|M:" $logPath`); - $logLines = explode("\n", `LC_ALL=C egrep -h "Starting|DISCONNECT|Connect|Automatic" $logPath`); + $logLines = explode("\n", `egrep -h "Starting|DISCONNECT|Connect|Automatic" $logPath`); return $logLines; } @@ -788,11 +788,11 @@ function getName($callsign) { } $delimiter =" "; // exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); - exec("LC_ALL=C egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); + exec("egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); if (count($output) == 0) { $delimiter = "\t"; // exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); - exec("LC_ALL=C egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); + exec("egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); } if (count($output) !== 0) { $name = substr($output[0], strpos($output[0],$delimiter)+1); From 86f6566f1267d4445b2546ce13fd183fe82ac94d Mon Sep 17 00:00:00 2001 From: CT2JAY Date: Tue, 28 Feb 2017 02:43:56 +0000 Subject: [PATCH 3/3] Creating a TMP file with all used Callsigns and Names --- include/functions.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/include/functions.php b/include/functions.php index 919ef16..a494f99 100644 --- a/include/functions.php +++ b/include/functions.php @@ -781,22 +781,41 @@ function getName($callsign) { return "---"; } + $TMP_CALL_NAME = "/tmp/Callsign_Name.txt"; + if (file_exists($TMP_CALL_NAME)) { + $callsign = trim($callsign); + if (strpos($callsign,"-")) { + $callsign = substr($callsign,0,strpos($callsign,"-")); + } + $delimiter =" "; + exec("egrep -m1 '".$callsign.$delimiter."' ".$TMP_CALL_NAME, $output); + if (count($output) !== 0) { + $name = substr($output[0], strpos($output[0],$delimiter)); + $name = substr($name, strpos($name,$delimiter)); + return $name; + } + } + if (file_exists(DMRIDDATPATH)) { $callsign = trim($callsign); if (strpos($callsign,"-")) { $callsign = substr($callsign,0,strpos($callsign,"-")); } $delimiter =" "; -// exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); exec("egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); - if (count($output) == 0) { + if (count($output) == 0) { $delimiter = "\t"; -// exec("grep -P '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); exec("egrep -m1 '".$callsign.$delimiter."' ".DMRIDDATPATH, $output); } if (count($output) !== 0) { $name = substr($output[0], strpos($output[0],$delimiter)+1); $name = substr($name, strpos($name,$delimiter)+1); + + $fp = fopen($TMP_CALL_NAME .'.TMP', 'a'); + $TMP_STRING = $callsign .' ' .$name; + fwrite($fp, $TMP_STRING.PHP_EOL); + fclose($fp); + exec('sort ' .$TMP_CALL_NAME.'.TMP' .' ' .$TMP_CALL_NAME .' | uniq > ' .$TMP_CALL_NAME); return $name; } else return "---";