Skip to content

Commit 6cec35d

Browse files
authored
Merge pull request #1 from drbyte/patch-1
Avoid open file handles
2 parents 43da6f5 + 2eb369b commit 6cec35d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

server.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,27 @@ function get_valet_site_path($valetConfig, $siteName, $domain)
130130
$valetSitePath = null;
131131
foreach ($valetConfig['paths'] as $path) {
132132
if ($handle = opendir($path)) {
133+
$dirs = [];
133134
while (false !== ($file = readdir($handle))) {
134135
if (! is_dir($path.'/'.$file)) continue;
135136
if (in_array($file, ['.', '..', '.DS_Store'])) continue;
137+
$dirs[] = $file;
138+
}
139+
closedir($handle);
136140

137-
// match dir for lowercase, because Nginx only tells us lowercase names
138-
if (strtolower($file) === $siteName) {
139-
$valetSitePath = $path.'/'.$file;
140-
break;
141+
// Note: strtolower used below because Nginx only tells us lowercase names
142+
foreach ($dirs as $dir) {
143+
if (strtolower($dir) === $siteName) {
144+
// early return when exact match for linked subdomain
145+
return $path.'/'.$dir;
141146
}
142147

143-
if (strtolower($file) === $domain) {
144-
$valetSitePath = $path.'/'.$file;
148+
if (strtolower($dir) === $domain) {
149+
// no early return here because the foreach may still have some subdomains to process with higher priority
150+
$valetSitePath = $path.'/'.$dir;
145151
}
146152
}
147-
closedir($handle);
148-
153+
149154
if ($valetSitePath) {
150155
return $valetSitePath;
151156
}

0 commit comments

Comments
 (0)