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

Storing templates in MySql database

 
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
Magnus
Smarty n00b


Joined: 08 Oct 2003
Posts: 2

PostPosted: Wed Oct 08, 2003 12:23 am    Post subject: Storing templates in MySql database Reply with quote

Hello.

I'm not here to ask how to do it (found instructions with search, thanks), but how it affects the speed? I'm creating a small CMS for my own projects and possibly for commercial use and I wish that the users were easily able to create new templates and modify the old ones. Using database stored templates for that seems like a good idea.

How big might be the speed difference when comparing using template files and templates taken from database (talking about optimized queries)? I'm worried that when many people try to access the same uncatched page, it might result a half-loaded design and info.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Oct 08, 2003 12:48 am    Post subject: Reply with quote

I have never seen that problem personally--I doubt it would really be a big concern, though. At worst, a page refresh should fix it Smile

A couple of comments: (assumes caching and that you are not forcing compiles)

1) the template is retrieved from the db only when it is altered--otherwise, only the timestamp is looked up (assuming you implement timestamp capability). This is the ONLY case a template is retrieved from db.

2) if cache file exists, then the db is not hit at all.

3) if cache does not exist but template has already been compiled, then the compiled template is run from the filesystem, not the db.

That said, on the same hardware, a db based template resource will take longer than a file based template, period. Fortunately, the overhead is typically very low (filemtime vs. abstracted db call for timestamp). Fortunately, those situations (like compilation) where the biggest hit would be felt should occur very infrequently.

The reason to choose the db option (IMHO) is for flexibility and to integrate into/with another solution. The small efficiency loss is worth it if those things are meaningful to your situation. On the other hand, you should be aware that any type of resource access where the source medium is not a filesystem makes template editing less convenient, so be prepared to provide adequate tools to your users! (I like the htmlArea wysiwyg control for that purpose [with a BSD style license to boot!] )
Back to top
View user's profile Send private message
Magnus
Smarty n00b


Joined: 08 Oct 2003
Posts: 2

PostPosted: Wed Oct 08, 2003 1:54 am    Post subject: Reply with quote

Thanks for the reply. Yes, I'm planning to use htmlArea- my only concern is that it is not XHTML compatible, but it seems that the new beta version fixes it (if you leave out the <font> tags).

I'm prepared to take a little performance hit, since I have saved some 'power' with php code optimisations. I think we can discuss more about it in about a week or two, when I start implementing the database stored templates system Wink
Back to top
View user's profile Send private message
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