Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Fatal error: Call to undefined function content_...

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Lemon Juice
Smarty Pro


Joined: 24 May 2006
Posts: 108

PostPosted: Wed Jul 04, 2012 7:02 am    Post subject: Fatal error: Call to undefined function content_... Reply with quote

I've been experiencing a strage problem with Smarty on one site for a few months - first it was 3.1RC but last week I upgraded to 3.1.10 and it's still there. After I upload new tpl files to the server and I visit the changed pages in the browser I get an error like this:

Code:
Fatal error: Call to undefined function content_4fedd7f531ac27_65199373() in /cache/smarty/templates_c/4bd61679fd0dcbb6e02969f886243a1accf8006c.file.produkt.tpl.php on line 151


After I reload the page everything is working fine. And this is the problematic code in the compiled template:

Code:
<?php /*  Call merged included template "inc/kategorie-box.tpl" */
$_tpl_stack[] = $_smarty_tpl;
 $_smarty_tpl = $_smarty_tpl->setupInlineSubTemplate("inc/kategorie-box.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null, array('box_name'=>htmlspecialchars($_smarty_tpl->tpl_vars['kategoriaBox']->value->name, ENT_QUOTES, 'UTF-8', true),'podkategorie'=>$_smarty_tpl->tpl_vars['kategorieBox']->value), 0, '10768097264fedd7f510e915-91572931');
content_4ff3e2899a21e1_01321222($_smarty_tpl);
$_smarty_tpl = array_pop($_tpl_stack); /*  End of included template "inc/kategorie-box.tpl" */?>


Of course, content_4fedd7f531ac27_65199373 is now content_4ff3e2899a21e1_01321222 because smarty recompiled the template. Because I noticed this happening only on one server I suspect this is can be a problem with my hosting company's home made opcode cache. It looks like smarty updates a compiled file while the server still executes the old one. The problem doesn't occur always but often enough to be irritating.

The question is - can something be done about this? I don't know if it's smarty's fault or server fault.
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Jul 04, 2012 7:35 am    Post subject: Reply with quote

Have you deleted the compiled templates after upgrading? Otherwise the new smarty-version simply couldn't understand the old compiled templates.

If the hoster's opcode cache bypasses the filesystem (like APC.stat=0 would do), you may be facing a problem.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Lemon Juice
Smarty Pro


Joined: 24 May 2006
Posts: 108

PostPosted: Wed Jul 04, 2012 9:08 am    Post subject: Reply with quote

rodneyrehm wrote:
Have you deleted the compiled templates after upgrading? Otherwise the new smarty-version simply couldn't understand the old compiled templates.

Sure. Besides, the problem occurs even when I don't do any upgrades.

rodneyrehm wrote:
If the hoster's opcode cache bypasses the filesystem (like APC.stat=0 would do), you may be facing a problem.

I'm not sure how it works exactly but certainly not like APC.stat=0 because after I upload new files the changes are reflected immediately, it is only sometimes that smarty seems to get out of sync and throws an error like this. Possibly they cache the files under certain circumstances.

What php function/construct does smarty use to execute the compiled template file? include, require, eval, or something else?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Jul 04, 2012 9:46 am    Post subject: Reply with quote

Lemon Juice wrote:
What php function/construct does smarty use to execute the compiled template file? include, require, eval, or something else?


Code:
include($_template->compiled->filepath);


smarty_internal_templatebase.php line 165
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Lemon Juice
Smarty Pro


Joined: 24 May 2006
Posts: 108

PostPosted: Wed Jul 04, 2012 12:35 pm    Post subject: Reply with quote

Thanks, I'll be watching this. For now I think I'll have to clear all compiled templates after each update as a workaround.
Back to top
View user's profile Send private message
MountainOfSea
Smarty n00b


Joined: 04 Nov 2012
Posts: 2

PostPosted: Sun Nov 04, 2012 10:42 am    Post subject: I think this is a bug of smarty Reply with quote

In smarty/libs/sysplugins/smarty_internal_templatebase.php, Line 160:
Code:
                   
                    if (!$_template->compiled->loaded) {
                        include($_template->compiled->filepath);
                        if ($_template->mustCompile) {
                            // recompile and load again
                            $_template->compileTemplateSource();
                            include($_template->compiled->filepath);
                        }   
                        $_template->compiled->loaded = true;
                        ......


If you have enabled some cache of opcode of php, this will be a problem. The first include will always take control of the compiled file. If change these lines to followings then it will be OK:
Code:

                    if (!$_template->compiled->loaded) {
                        if ($_template->mustCompile()) {       //Notice! Use mustCompile() function!
                            // recompile and load again
                            $_template->compileTemplateSource();
                        }   
                        include($_template->compiled->filepath);
                        $_template->compiled->loaded = true;
                        ......


Last edited by MountainOfSea on Sun Nov 04, 2012 10:58 am; edited 1 time in total
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Sun Nov 04, 2012 10:47 am    Post subject: Reply with quote

We'll have to find another solution for op-code cache invalidation. The loaded file itself can alter the state of mustCompile (depending on the time the file was cached when $caching === Smarty::CACHING_LIFETIME_SAVED).

Which op-code cache are you using?
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
MountainOfSea
Smarty n00b


Joined: 04 Nov 2012
Posts: 2

PostPosted: Sun Nov 04, 2012 11:03 am    Post subject: Reply with quote

rodneyrehm wrote:
We'll have to find another solution for op-code cache invalidation. The loaded file itself can alter the state of mustCompile (depending on the time the file was cached when $caching === Smarty::CACHING_LIFETIME_SAVED).

Which op-code cache are you using?


eAccelerator v0.9.6.1.

I think that use mustCompile() function to test before loading file will be more easier to understand, and the code will run correctly despite of whether you are using opcode cache.

Maybe there are some better ways to invalidate op-code cache, just some suggestions.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4692
Location: Hamburg / Germany

PostPosted: Sun Nov 04, 2012 3:27 pm    Post subject: Reply with quote

This is a problem of just of eAccelerator that it sometimes does not see the fresh recompiled file on the second include.
Other PHP caches like APC have no problem.

A call to mustCompile() is no option as it can not detect all file dependencies.
Back to top
View user's profile Send private message
kowach
Smarty Rookie


Joined: 26 Jan 2011
Posts: 12

PostPosted: Wed Oct 15, 2014 11:52 am    Post subject: Reply with quote

I am getting same error on Smarty 3.1.20 (on 3.1.13 was just fine) and APCu 4.0.4.

Code:

foreach ($data as &$item)
{
    // ID goes 1,2,2,...
    $cache_id = $item['ID']; // some ID-s are same
    if(!$smarty->isCached("tooltip.tpl", $cache_id)) {
         // do database

    }
   
    $item['tooltip_html'] = $smarty->fetch("tooltip.tpl", $cache_id);
}




PHP Fatal error: Call to undefined function content_543e4a3aa0a041_93392201() in Smarty-3.1.20/libs/sysplugins/smarty_internal_templatebase.php on line 296

In first request when cache is created, in the loop when ID repeats, where cache was just created on that previous ID I get PHP Fatal error.

On second request on page there is no error.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4692
Location: Hamburg / Germany

PostPosted: Wed Oct 15, 2014 8:27 pm    Post subject: Reply with quote

This fix is now in the SVN trunk and will later be included in 3.1.21
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs 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