|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
dlanz Smarty Rookie
Joined: 14 May 2015 Posts: 5
|
Posted: Thu May 14, 2015 5:36 pm Post subject: Smarty: unable to write file (Occasionally) |
|
|
I've been dropped a project which makes use of Smarty 3.1.21 without much knowledge of Smarty to start with. I've been seeing log errors for a select few pages albeit inconsistently.
Nearly every time I visit one of the afflicted pages everything functions as expected and no errors are logged. Some how I occasionally see errors in the log similar to:
Code: | Uncaught --> Smarty: unable to write file /path/to/compiled/template |
When ever I double check the existence and permissions of the particular file everything is readable and writable from the root to the file. My compiled template directory is above root, but I've check the permissions up the tree from both locations.
Here is how I define my smarty object in my config file:
Code: |
$tpl = new Smarty();
$tpl->caching = false;
$tpl->compile_check = false;
//$tpl->force_compile = true;
$tpl->template_dir = $path_docroot.'/templates';
$tpl->compile_dir = '/path/to/smarty/templates_c';
$tpl->cache_dir = '/path/to/smarty/cache';
$tpl->config_dir = '/path/to/smarty/configs';
/**
* Clear all cached/compiled templates
*/
// for smarty version 3.0.6
$tpl->clearCompiledTemplate(); |
The site in question has many pages which are dynamic and specific to the user who is logged in. I have caching disabled, compile_check disabled and clear compiled templates because I don't want one user to be served the compiled template of another user (When I commented out the line to clear compiled templates I actually logged in and saw the login screen for another user. I immediately reverted the change and stuck with what was "working")
I'm not sure what the correct declarations are for using smarty in a dynamic multi-user environment, but was hoping for some pointers. I feel there is some sort of race condition between template compilation and clearing the templates with each connection. I'm just too unsure (and ignorant) of some of the smarty functions and how they all play with each other in tandem. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu May 14, 2015 11:18 pm Post subject: |
|
|
Code: | $tpl->clearCompiledTemplate(); |
Is causing the problems and kill all performance of Smarty. It will delete all already compiled templates of the whole project on a call of any page. It does not make sense as this function is more a sort of maintenance function. Just remove it.
Use
Code: | $tpl->compile_check = true; |
With it Smarty will automatically recompile modified templates.
In Smarty 3 you should use setter function to configure your folders
Code: | $tpl->setTemplateDir( $path_docroot.'/templates');
$tpl->setCompileDir( '/path/to/smarty/templates_c');
$tpl->setCacheDir( '/path/to/smarty/cache');
$tpl->setConfigDir('/path/to/smarty/configs'); |
The properties should not be accessed directly.
See http://www.smarty.net/docs/en/variable.template.dir.tpl |
|
Back to top |
|
dlanz Smarty Rookie
Joined: 14 May 2015 Posts: 5
|
Posted: Fri May 15, 2015 12:38 pm Post subject: |
|
|
Thank you, I just made the suggested changes. I will monitor the logs over the weekend and re-post a confirmation.
I guess a combination of having:
Code: | $tpl->compile_check = false; |
and
Code: | $tpl->clearCompiledTemplate(); |
caused old variable values to be retained across user sessions?
Or would caching set true be required to create that behavior?
I'm 99.99% sure I did not have caching set to true when I noticed that. But I suppose there is a chance I over looked it at that moment in time.
Thank you for your quick reply. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon May 18, 2015 3:55 am Post subject: |
|
|
Compiled templates contain no variable values.
They contain the template source compiled into PHP code.
If you enable caching then you will create cached templates which will contain the rendered html output including the variable values.
The content of a cached template gets displayed until it gets invalid or caching is disabled. |
|
Back to top |
|
dlanz Smarty Rookie
Joined: 14 May 2015 Posts: 5
|
Posted: Mon May 18, 2015 2:30 pm Post subject: |
|
|
I just checked the logs after the entire weekend and not a single entry pertaining to the behavior I mentioned.
Thank you very much for your help U.Tews. |
|
Back to top |
|
|
|
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
|