Skip to content
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

Fixing forced OpCache invalidation on every template include, which is resulting in fast raising wasted OpCache memory #1007 #1047

Merged
merged 9 commits into from
Aug 14, 2024
1 change: 1 addition & 0 deletions src/Resource/FilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function populate(Source $source, Template $_template = null) {
* @param Source $source source object
*/
public function populateTimestamp(Source $source) {
$path = false;
stephanlueckl marked this conversation as resolved.
Show resolved Hide resolved
if (!$source->exists && $path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig)) {
$source->timestamp = $source->exists = is_file($path);
}
Expand Down
21 changes: 12 additions & 9 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,16 +241,19 @@ 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 forces a revalidation of the file in opcache or apc cache (if available)
*
*/
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, true);
} 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, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
}
if (defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($this->filepath));
Expand Down