-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mime] Close file handle #58163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mime] Close file handle #58163
Conversation
Did you actually run into the issue you describe? I would expect PHP to implicitly do the same already due to the fact that the method ends a few lines later. |
Yes, I have an import script for Pimcore (which is based on Symfony) which imports files from an FTP resource (source is an ERP system). For every file being imported, the MIME type gets determined. The script runs fine during the month when there are only a few changes in ERP and thus only a few files to be imported. But at the beginning of a new month, a lot of prices or other things get changed and thus a lot of files have to be processed in one process. And in those runs my error log looks like this:
Of course only one of those messages is from Symfony, the other one is from Pimcore but Pimcore closes the stream after saving the file, see https://github.com/pimcore/pimcore/blob/32f3f344a59ec3ddf8570c58443b9d2a86f25758/models/Asset.php#L798 But when I look at the PHP source code, maybe you are right because in https://github.com/php/php-src/blob/fad899e5662d0a929d8462dd8239b0489dd9b53f/ext/fileinfo/fileinfo.c#L400C14-L400C40 the stream gets opened and in https://github.com/php/php-src/blob/fad899e5662d0a929d8462dd8239b0489dd9b53f/ext/fileinfo/fileinfo.c#L415 it gets closed. But then I only wonder why in the PHP tests |
Were you able to run the patch in the affected environment? Did it actually make a difference? |
…nd optimize perf (nicolas-grekas) This PR was merged into the 7.2 branch. Discussion ---------- [Mime] Cache finfo objects to reduce open file handles and optimize perf | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Inspired by #58163 Commits ------- 5a1be29 [Mime] Cache finfo objects to reduce open file handles and optimize perf
Currently the
finfo
file handle does not get closed which can result in the errorToo many open files in [...]/vendor/symfony/symfony/src/Symfony/Component/Mime/FileinfoMimeTypeGuesser.php
if
guessMimeType()
gets called for more thanulimit -n
files.According to https://stackoverflow.com/a/32102146 the file handle can be closed with
unset()
- as it is done in PHP's unit tests