From 3726732cfa009857e14e63b471d4370a18f6b385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 8 Jul 2017 21:33:32 +0200 Subject: [PATCH] Reading list of inc files: performance improvements (fewer popen) --- loader.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/loader.php b/loader.php index cf7cba9..499bd2d 100644 --- a/loader.php +++ b/loader.php @@ -33,13 +33,21 @@ function modulekit_process_inc_files($basepath, $include) { foreach($include as $type=>$list) { $ret[$type] = array(); + if (!sizeof($list)) { + continue; + } + + $cmd = "cd " . escapeshellarg($modulekit_root . $basepath) . " 2>/dev/null"; + foreach ($list as $type_list) { - $f = popen("cd " . escapeshellarg($modulekit_root . $basepath) . " 2>/dev/null; ls " . escapeshellarg($type_list) . " 2>/dev/null", "r"); - while ($r = fgets($f)) { - $ret[$type][] = trim($r); - } - fclose($f); + $cmd .= "; ls " . escapeshellarg($type_list) . " 2>/dev/null"; + } + + $f = popen($cmd, "r"); + while ($r = fgets($f)) { + $ret[$type][] = trim($r); } + fclose($f); } return $ret;