8000 [Mime] Cache finfo objects to reduce open file handles and optimize perf · symfony/symfony@6c7b026 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c7b026

Browse files
[Mime] Cache finfo objects to reduce open file handles and optimize perf
1 parent 44395ab commit 6c7b026

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Symfony/Component/Mime/FileinfoMimeTypeGuesser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
2323
{
24+
private static $finfoCache = [];
25+
2426
/**
2527
* @param string|null $magicFile A magic file to use with the finfo instance
2628
*
@@ -46,7 +48,7 @@ public function guessMimeType(string $path): ?string
4648
throw new LogicException(\sprintf('The "%s" guesser is not supported.', __CLASS__));
4749
}
4850

49-
if (false === $finfo = new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile)) {
51+
if (false === $finfo = self::$finfoCache[$this->magicFile] ??= new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile)) {
5052
return null;
5153
}
5254
$mimeType = $finfo->file($path);

0 commit comments

Comments
 (0)
0