8000 Fix performance (PHP5) and memory (PHP7) issues when using token_get_all by nicolas-grekas · Pull Request #17377 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix performance (PHP5) and memory (PHP7) issues when using token_get_all #17377

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

Merged
merged 2 commits into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add gc_mem_caches() call for PHP7 after itoken_get_all() as new memor…
…y manager will not release small buckets to OS automatically
  • Loading branch information
Peter Ward authored and nicolas-grekas committed Jan 15, 2016
commit e555aade120b0950ee63ed10e792dd602e749214
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function extract($directory, MessageCatalogue $catalog)
$files = $finder->files()->name('*.php')->in($directory);
foreach ($files as $file) {
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ public static function fixNamespaceDeclarations($source)
$rawChunk .= "}\n";
}

return $output.self::compressCode($rawChunk);
$output .= self::compressCode($rawChunk);

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
unset($tokens, $rawChunk);
gc_mem_caches();
}

return $output;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/ClassLoader/ClassMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public static function createMap($dir)

$classes = self::findClasses($path);

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}

foreach ($classes as $class) {
$map[$class] = $path;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,12 @@ public static function stripComments($source)

$output .= $rawChunk;

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
unset($tokens, $rawChunk);
gc_mem_caches();
}

return $output;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public function load($file, $type = null)
$collection->addResource(new FileResource($path));
$collection->addCollection($this->loader->load($class, $type));
}
if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}

return $collection;
}
Expand Down
0