Reputation: 59616
I am working on an old legacy PHP application using Smarty. I am not familiar with Smarty. Hence my questions.
I understand that Smarty templates are compiled into PHP. Then, they are invoked with some data to generate an output. The generated PHP is compiled as part of this process.
APC (and other cache solution) avoid the recompilation of PHP between user requests.
i) If I call Smarty with a raw template, it will compile it into PHP first, then into opcode, right?
ii) If a cache system like APC is enabled in my PHP application, and if the template has already been invoked (i.e., compiled) in the past:
a) Will Smarty be smart enough to not recompile the template into PHP at each user request?
b) Will the opcode of the compiled template's PHP be re-used via APC?
Why am I asking these questions? This legacy application has been implemented a long time ago (some parts before 2010). They have implemented a precompilation system of all their Smarty template and copied them in some directory of the application to invoke generated PHP code directly.
I believe it could have made sense then regarding performance, but now, since opcode cache solutions are still available, does it still make sense? Could we get rid of this precompilation process?
Upvotes: 2
Views: 350
Reputation: 97898
Smarty compiles all the .tpl
files into PHP on first use, and places the result in a configured cache directory. These PHP files are then include
d just like any other PHP file, so there is nothing special APC/OpCache would need to do to be invoked for them.
On subsequent requests, Smarty will check if the timestamp of the underlying .tpl
file has changed, and re-compile if it has; otherwise, it will just leave the existing PHP file in place. This behaviour can be turned off, e.g. on a production server where files should not be edited (this setting was available in Smarty 2 as well, it's nothing new).
I'm not sure what the manual compilation process you describe was trying to achieve; it sounds from your description to just be replicating what Smarty already does, but with a small boost for the first hit on each template by "warming the cache". It certainly has nothing to do with the presence or absence of APC/OpCache - that won't change how often Smarty compiles things into PHP, only how often PHP compiles PHP into "op codes".
There may be some other trick being used which you haven't spotted / described, or it may be that the previous programmer of the system didn't know what they were doing and over-complicated things.
Upvotes: 3