Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 349ea04

Browse filesBrowse files
committed
bug #34918 [Translation] fix memoryleak in PhpFileLoader (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Translation] fix memoryleak in PhpFileLoader | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This happens when running the test suite with opcache disabled (as it is the case by default since `opcache.enable_cli=0`). Doing this "require" in a loop (for each test case) compiles the file at each iteration and doesn't reclaim memory (there is no garbage collector for opcodes). Commits ------- 5c9e3ba [Translation] fix memoryleak in PhpFileLoader
2 parents c90cf33 + 5c9e3ba commit 349ea04
Copy full SHA for 349ea04

File tree

1 file changed

+15
-1
lines changed
Filter options

1 file changed

+15
-1
lines changed

‎src/Symfony/Component/Translation/Loader/PhpFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Loader/PhpFileLoader.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@
1818
*/
1919
class PhpFileLoader extends FileLoader
2020
{
21+
private static $cache = [];
22+
2123
/**
2224
* {@inheritdoc}
2325
*/
2426
protected function loadResource($resource)
2527
{
26-
return require $resource;
28+
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
29+
self::$cache = null;
30+
}
31+
32+
if (null === self::$cache) {
33+
return require $resource;
34+
}
35+
36+
if (isset(self::$cache[$resource])) {
37+
return self::$cache[$resource];
38+
}
39+
40+
return self::$cache[$resource] = require $resource;
2741
}
2842
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.