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

Template cache corruption / collision (+ workaround)

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
dthought
Smarty Regular


Joined: 21 Apr 2003
Posts: 55
Location: Melbourne, Australia

PostPosted: Thu Mar 25, 2004 1:00 am    Post subject: Template cache corruption / collision (+ workaround) Reply with quote

Here's an issue that may be of interest to anyone using Smarty outside of the webserver process.

The situation:
I'm working with a few others on a system that does user management and billing etc.. We're using Smarty to generate the interface, as well as to render templates that get sent as HTML mail, the HTML for invoices sent as PDF files via a PDF renderer and so on - in other words, Smarty is doing a lot of different things.

We'd noticed that every now and then in an email that gets sent out, or a generated invoice PDF - the contents was corrupted, or just plain incorrect (eg. generating the same result over and over no matter how many times you regenerated an invoice)! This issue bugged us for quite some time. We resorted to simply flushing the /templates_c/ on a semi-regular basis, and that seemed to fix it - or at least, alleviate the problem temporarily.

The reason:
We eventually found out why this problem was being caused, and the details are as follows:

* Normal stuff like admin generated invoices or email are run from the apache process
* The email / invoice generation etc. is a cron job - running as root

It seems that having both the apache user and the root user generating things upsets Smarty's cache greatly. The root user can gleefully overwrite compiled templates, which then apache cannot recreate due to it being a root-owned file. This is how the template corruption would occur - from the war between these two users (-;

The solution:
We found an easy way around this whole issue, and it's recommended if you plan on using Smarty during a cron job, as well as via another user, eg. an apache webserver:
Simply detect if you are running from the shell, and set $smarty->compile_dir to a separately named template cache directory - in our case we chose, /templates_sh_c/ - look! No more corruption issues.

I'm sure there's a better way around this (maybe even a way for Smarty itself to handle this sort of thing). However, this might help anyone else in a similar situation and who's pulling their hair out because their templates cache has gone crazy.
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 -> 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