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

Compile to 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 -> Smarty Development
View previous topic :: View next topic  
Author Message
PhpNut
Smarty n00b


Joined: 14 Jun 2003
Posts: 4

PostPosted: Sat Jun 14, 2003 10:37 pm    Post subject: Compile to Database. Reply with quote

I have been looking for a way to save compiled files the a database I searched the forums and looked the the Smarty FAQ. I found this in the FAQ.

Q: Can I force Smarty to store compiled templates into database rather than file on the disk?
A: Not yet... But perhaps you could find someone to implement it Wink
A: You shouldn't, it will be a great performance disadvantage, because PHP cannot execute them directly from database.

Has anyone even tried to do this. I am not too worried about the performance issues right not I am looking for a way to store the compiled files without having to chmod the file system.

I have been kicking around the idea of hacking Smarty.Class.php and adding the ability to do this. Setting a new var in the class

var $compile_save_type or something like that.

Then edit:

Code:

function clear_compiled_tpl
function config_load
function _get_compile_path
function _write_compiled_template
function _compile_template
function fetch
function _process_template


And any other functions that may be needed to add a check for the compile_save_type and save or retrieve compiled template to or from the database instead of file system.

Besides the performance issue can anyone see a reason not to do this?

Larry E. Masters
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun Jun 15, 2003 2:11 am    Post subject: Reply with quote

It would be a huge performance disadvantage. Instead of including PHP files from the local file system, you would be querying a database source (possibly over TCP), then running an eval() statement on the resulting code. This would most certainly be many times slower. Another disadvantage is you could not use a PHP accelerator.

Monte
Back to top
View user's profile Send private message Visit poster's website
PhpNut
Smarty n00b


Joined: 14 Jun 2003
Posts: 4

PostPosted: Sun Jun 15, 2003 2:49 am    Post subject: Reply with quote

mohrt wrote:
It would be a huge performance disadvantage. Instead of including PHP files from the local file system, you would be querying a database source (possibly over TCP), then running an eval() statement on the resulting code. This would most certainly be many times slower. Another disadvantage is you could not use a PHP accelerator.

Monte


I would make it an option for the end user.

Basically the content would be cached using smarty. So the pages being displayed would not use the compiled files all the time, only if content on the site has changed. If the sites content changes often then the end user may want to use the file system instead. But I would like to give them the option.

And the cached pages would be stored in the database unless user wants to use the file system.


Larry E. Masters
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Sun Jun 15, 2003 5:41 am    Post subject: Reply with quote

It sounds a lot more interesting than it really is. I think it is magnificently useless and wasteful of resources. What you should consider is that compiled and cached files are not user resources in the typical sense, but instead form part of Smarty's working set and are thus temporary. In fact, you are likely best off not even considering that they exist at all and instead think of them as Smarty's private data. In a perfect world, they probably wouldn't be directly available as a user resource but would be hidden by the engine entirely.

Let me ask this: what does your goal actually achieve, or better, what real-life problem does it solve? Not having to chmod the filesystem? That's like carrying the parts of your car around because you don't want to put any gas in it. If you want to walk, leave the car at home Wink

In the end, I think you are making a lot of work for yourself, slowing down your system yet not accruing any real world benefit.

Good luck!

PS: If you are quixotic about this, you may consider creating a PHP user stream to read write your db so that you can remain compatabile with the builtin filesystem functions. Though still slower than the filesystem, at least your db stored data will behave as a file as far as PHP is concerned. Best of all, you wouldn't have to change Smarty very much to support it (if at all) since you would be able to set your paths to something like: mydbhandler://path instead of using a normal file path.
Back to top
View user's profile Send private message
mikeken
Smarty Regular


Joined: 13 Aug 2003
Posts: 57
Location: MN

PostPosted: Fri Aug 22, 2003 4:08 am    Post subject: Reply with quote

boots wrote:
What you should consider is that compiled and cached files are not user resources in the typical sense, but instead form part of Smarty's working set and are thus temporary. In fact, you are likely best off not even considering that they exist at all and instead think of them as Smarty's private data.


Thats exactly the way I do it. I have a php file appended in my php.ini file with the template_c and cache dirs set, and then I manually set the actual template name in each php file.

I have no idea they exist. Sorta
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
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 -> Smarty Development 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