Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

memcache shared cache

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jetter
Smarty Rookie


Joined: 01 Feb 2016
Posts: 5

PostPosted: Mon Feb 01, 2016 12:31 pm    Post subject: memcache shared cache Reply with quote

Hello,

I am working with a high~ish traffic website using smarty 2.6.9
The site run on 3 web servers, each has its local file system for compiled templates, .tmpl.php and .tmpl.inc files, and share the cached version in memcache.

As the servers are moving to php 5.6, from php5.3, we installed the latest version of Smarty 2.6.29.

As we did, we started receiving errors like those:
PHP Fatal error: Call to undefined function _smarty_tplfunc_6e90f303cffaaac879c22c312cb36aef_0()

We then spent a bit of time looking into this and quickly had to check the internals.
I understand this means the "compiled" is out of sync with the "cached", but this leads me to 2 questions I cannot get my head around:

- On the 3 servers, each compile files is called the same, but in the source, each _smarty_tplfunc_ function name's hash, aka the "cache serial" is different.
As those are called for "nocache" blocks from the cached files, those cached files being shared, how can it work?
The shared cache file will load successfully the .inc library ion the 3 servers, but only on one the _cache_serial will be found, failing on the other 2 servers. And in this case, isn't the cache file rebuilt according to whichever server is being used and its value of _cache_serial?

- the error we got was due to a change in the internal core.read_cache_file.php. In version 2.6.9, there was a block returning "false" if the cache_serial was not found in the loaded .inc file (lines 93-102):
Code:

 foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
        if (empty($smarty->_cache_serials[$_include_file_path])) {
            $smarty->_include($_include_file_path, true);
        }

        if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {
            /* regenerate */
            return false;
        }
    }


I tried to find some info about my problem on the forum, but couldn't find anything relevant.
I am now a bit at a loss, is there something very obvious we didn't do right? ARe we not supposed to share cached files across physical servers?
Even if we do, does this mean Smarty requires one cached file per server? Hence making the sharing irrelevant? Or worse, is Smarty, in my case, rewriting every cache file for each call made by a new server not sharing the current cache file's cache_Serial?

Any help would be much appreciated!

Jetter
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 01, 2016 4:40 pm    Post subject: Reply with quote

When you updated smarty, did you clear out compiled and cached files? If not do that first, see if it clears up the errors. If you are caching to memcache, be sure to clear those too. It looks like upon initial inspection, your current compiled/cache files are no longer compatible with the update.
Back to top
View user's profile Send private message Visit poster's website
jetter
Smarty Rookie


Joined: 01 Feb 2016
Posts: 5

PostPosted: Mon Feb 01, 2016 9:11 pm    Post subject: Reply with quote

Hi mohrt, both compile and cache storage were wiped clean. All created fine, but after a few seconds the described behaviour happens.
Surely, the problem must be linked to each server having their own set of compiled file, each with their own set of tpl_func names?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Feb 02, 2016 10:28 pm    Post subject: Reply with quote

It is possible that you have uncovered a bug. You should be able to share cached files across servers if they are all serving up the same data. I would think the hashes for compiled files would match too. 2.6.9 to 2.6.29 is quite a jump.
Back to top
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Feb 03, 2016 1:48 am    Post subject: Reply with quote

Question: Are you sure your servers have correct date/time?
Back to top
View user's profile Send private message
jetter
Smarty Rookie


Joined: 01 Feb 2016
Posts: 5

PostPosted: Wed Feb 03, 2016 11:26 am    Post subject: Reply with quote

AnrDaemon,
The 3 servers keep their times through ntp and are all in sync.

Mohrt,
This happens also on 2.6.9.
whenever a compile file is created (.tmpl.php and .tmpl.inc) from a template, its cache_serial is generated using md5(uniqid('Smarty')), hence different on all web server.

How can a shared cached file, using only one out of the many hash created, work?

The difference between 2.6.9 and 2.6.29 is the code checking the expected _cache_serial against the loaded one:
if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {
/* regenerate */
return false;
}

On 2.6.9 it would invalidate, on 2.6.29 it would end up calling a non-existing function
Back to top
View user's profile Send private message
Achylle78
Smarty n00b


Joined: 06 Mar 2016
Posts: 1

PostPosted: Mon Mar 07, 2016 5:00 am    Post subject: Reply with quote

jetter wrote:
Hi mohrt, both compile and cache storage were wiped clean. All created fine, but after a few seconds the described behaviour happens paris shuttle .
Surely, the problem must be linked to each server having their own set of compiled file, each with their own set of tpl_func names?


It's certain!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP