summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Lueckl <stephan.lueckl@niceshops.com>2024-08-14 21:58:51 +0200
committerGitHub <noreply@github.com>2024-08-14 21:58:51 +0200
commit1ccfca17d64d6a6b257408fb45776c4cb3547260 (patch)
tree3daa1cd826cd73129dd63e11138806ada11fc353
parentd6153d4d4da7a9df4c2965d1b491044328d331ad (diff)
downloadsmarty-1ccfca17d64d6a6b257408fb45776c4cb3547260.tar.gz
smarty-1ccfca17d64d6a6b257408fb45776c4cb3547260.tar.bz2
smarty-1ccfca17d64d6a6b257408fb45776c4cb3547260.zip
Fixing forced OpCache invalidation on every template include, which is resulting in fast raising wasted OpCache memory #1007 (#1047)
* Fixing forced OpCache Invalidation on every call, which is resulting in fast raising wasted memory * Fix undefined $path variable warning --------- Co-authored-by: Daniel Metzner <daniel.metzner@niceshops.com>
-rw-r--r--src/Resource/FilePlugin.php9
-rw-r--r--src/Template/Compiled.php21
2 files changed, 18 insertions, 12 deletions
diff --git a/src/Resource/FilePlugin.php b/src/Resource/FilePlugin.php
index 7fd8667d..c5959578 100644
--- a/src/Resource/FilePlugin.php
+++ b/src/Resource/FilePlugin.php
@@ -56,11 +56,14 @@ class FilePlugin extends BasePlugin {
* @param Source $source source object
*/
public function populateTimestamp(Source $source) {
- if (!$source->exists && $path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig)) {
- $source->timestamp = $source->exists = is_file($path);
+ $path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig);
+ if (!$source->exists) {
+ $source->exists = ($path !== false && is_file($path));
}
- if ($source->exists && $path) {
+ if ($source->exists && $path !== false) {
$source->timestamp = filemtime($path);
+ } else {
+ $source->timestamp = 0;
}
}
diff --git a/src/Template/Compiled.php b/src/Template/Compiled.php
index caee87f3..5a07db0e 100644
--- a/src/Template/Compiled.php
+++ b/src/Template/Compiled.php
@@ -136,7 +136,7 @@ class Compiled extends GeneratedPhpFile {
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) {
@@ -241,16 +241,19 @@ class Compiled extends GeneratedPhpFile {
* 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));