Skip to content

Commit

Permalink
Fixing forced OpCache Invalidation on every call, which is resulting …
Browse files Browse the repository at this point in the history
…in fast raising wasted memory

smarty-php#1007
  • Loading branch information
stephanlueckl committed Jul 29, 2024
1 parent f6c1306 commit 263e4c5
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Template/Compiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function compileAndLoad(Template $_smarty_tpl) {
if ($this->exists && !$_smarty_tpl->getSmarty()->force_compile
&& !($_smarty_tpl->compile_check && $_smarty_tpl->getSource()->getTimeStamp() > $this->getTimeStamp())
) {
$this->loadCompiledTemplate($_smarty_tpl);
$this->loadCompiledTemplate($_smarty_tpl, false);
}

if (!$this->isValid) {
Expand Down Expand Up @@ -241,17 +241,20 @@ private function write(Template $_template, $code) {
* HHVM requires a workaround because of a PHP incompatibility
*
* @param Template $_smarty_tpl do not change/remove variable name, is used by compiled template
* @param bool $invalidateCachedFiles
*
*/
private function loadCompiledTemplate(Template $_smarty_tpl) {

if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, false);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
private function loadCompiledTemplate(Template $_smarty_tpl, bool $invalidateCachedFiles = true) {

if ($invalidateCachedFiles) {
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, false);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
}
if (defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($this->filepath));
} else {
Expand Down

0 comments on commit 263e4c5

Please sign in to comment.