将我的Xubuntu从13.04升级到13.10后,我遇到了Smarty和PHP的问题。
编辑模板后,基本上Smarty模板会延迟5-7秒重新编译。
我将系统时间(date
)与PHP date(...)
进行了比较,时间戳相等。
PHP Version 5.5.3-1ubuntu2
如何解决?
示例代码:
require_once 'classes/Smarty-3.1.8/libs/Smarty.class.php';
$tpl = new Smarty();
// if I edit this template, changes shows up after
// 3-4 seconds which is very annoying
// there was no issue in xubuntu 13.04 / older php version!
$tpl->display('test.tpl');
修改
我仔细检查filemtime
是否正常工作,是。
答案 0 :(得分:2)
您可以启用opcache并设置:
opcache.revalidate_freq=0
问题是默认情况下,opcache仅在2秒后检查时间戳,并且在同一请求期间生成smarty编译模板,因此不会检查。
将opcache revalidate_freq设置为0会使opcache每次检查所有文件的时间戳,因此.tpl文件中的更改会立即显示。
编辑:我认为从Smarty v3.1.29起不再需要这样做了
答案 1 :(得分:0)
我找到了解决方案。
Acctionaly在xubuntu 13.10提供的最新PHP中默认启用了zend opcache,这导致了这个问题。
我不得不改变php的配置:
opcache.enable=0
现在一切都很好,模板在编辑后立即编译。