Peter Peter - 1 month ago 10
PHP Question

PHP and Smarty compile delay after upgrading system

After upgrading my Xubuntu from 13.04 to 13.10 I am experiencing issue error with Smarty and PHP.

Basically Smarty templates are recompiled with 5-7 seconds delay after I edit template.

I compared system time (

date
) with PHP's
date(...)
and timestamp is equal.

PHP Version 5.5.3-1ubuntu2


How to fix it?

Example code:

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');


Edit:

I double checked is
filemtime
working properly and it is.

Answer

You can keep opcache enabled and set:

opcache.revalidate_freq=0

The problem is that by default opcache only checks timestamps after 2 seconds, and the smarty compiled templates are generated during the same request so are not checked.

Setting opcache revalidate_freq to 0 makes opcache check timestamps for all files every time, so changes made in .tpl files show instantly.

Edit: I believe this is no longer necessary as of Smarty v3.1.29

Comments