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

Anyone notice that APC fails to cache any -compiled- files

 
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
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Thu Jul 21, 2011 12:36 pm    Post subject: Anyone notice that APC fails to cache any -compiled- files Reply with quote

You don't need CacheResource APC in some thread of this forum to produce this problem.

Around line 433 in sysplugins/smarty_internal_template.php

Code:

//if (function_exists('apc_compile_file')) var_exporT(apc_compile_file($this->getCompiledFilepath()));
                include($this->getCompiledFilepath ());


Please note that the first line is added to test APC
apc_compile_file always returns TRUE but such file isn't reported as compiled by apc.php

If I change 'include' to 'include_once', the compiled file get compiled and stored by APC. However, you can't use include_once in the code there, since Smarty will fail to re-include any templates.

I have tried changing what returned by getCompiledFilepath($_template).. but same result.

BTW, My platform is very dynamic, Smarty cache is always disabled.

This seems like a bug in APC, but I hope to find a way to get around this without fixing APC and waiting for php_apc.dll 64bit running on Windows.

One thing I can do is to tell Smarty to include_once at first call and then do include on the next call, but I really don't know whether APC will use the compiled file by include_once or just re-include the file again... This is probably useless then.
Back to top
View user's profile Send private message
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Thu Jul 21, 2011 12:46 pm    Post subject: Reply with quote

As expected, include_once gets APC to store a file in OPCODE, but sequence calls to include doesn't use the OPCODE, it read directly from file system.

I know this by looking at the Hits value in APC.php
However, it is still better than nothing.
At least this will speed up the first call to include_once in any HTTP request
Back to top
View user's profile Send private message
rodneyrehm
Administrator


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

PostPosted: Thu Jul 21, 2011 1:12 pm    Post subject: Reply with quote

With Smarty3.1 (DEV) you actually COULD replace the include by an include_once.
Back to top
View user's profile Send private message Visit poster's website
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Thu Jul 21, 2011 3:49 pm    Post subject: Reply with quote

Oh this is great! Thank you very much
Last time I switched to 3.1, I got many errors with my old apps.
but today I got only one error with a new application and framework.

Here is the place to replace
smarty_internal_templatebase.php around line:139-147
Code:

                    if (!$_template->compiled->loaded) {
                        include_once($_template->compiled->filepath);
                        if ($_template->mustCompile) {
                            // recompile and load again
                            $_template->compileTemplateSource();
                            include_once($_template->compiled->filepath);
                        }
                        $_template->compiled->loaded = true;
                    }
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Jul 21, 2011 4:02 pm    Post subject: Reply with quote

The second include must stay as it was. Otherwise templates recompiled because of modifcation will not be rendered at the current call.

Code:
                    if (!$_template->compiled->loaded) {
                        include_once($_template->compiled->filepath);
                        if ($_template->mustCompile) {
                            // recompile and load again
                            $_template->compileTemplateSource();
                            include($_template->compiled->filepath);
                        }
                        $_template->compiled->loaded = true;
                    }
Back to top
View user's profile Send private message
rodneyrehm
Administrator


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

PostPosted: Thu Jul 21, 2011 4:54 pm    Post subject: Reply with quote

In the event a template is included again, due to re-compilation, you also might want to tell APC to flush its cache for that file… http://www.php.net/manual/en/function.apc-delete-file.php (if apc.stat = 0)
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
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