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

Caching Smarty with a DB & Memcache.

 
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 -> Installation and Setup
View previous topic :: View next topic  
Author Message
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 12:36 am    Post subject: Caching Smarty with a DB & Memcache. Reply with quote

I'm currently using Smarty on PHP5.0.2/Smarty 2.6.6, however theres seems to be problems with using alternative caching mechanisms, such as described in the documentation. Any, workarounds tips? Confused
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


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

PostPosted: Tue Nov 09, 2004 1:16 am    Post subject: Reply with quote

What kind of problems?

There is a Turck MMCache implementation in this thread that may give you some tips.
Back to top
View user's profile Send private message
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 10:19 am    Post subject: Reply with quote

boots wrote:
What kind of problems?

There is a Turck MMCache implementation in this thread that may give you some tips.


I'm not sure whether its because of a modifcation as lightly mentioned in the changelog or whether its something else...

Quote:

Version 2.6.6 (Oct 13, 2004)
----------------------------

- fixed nocache-handling with nested includes (Lars Jankowfsky, messju)
- moved /libs/core to /libs/internals (boots)
- fixed more parsing problems (messju)


$smarty->cache_handler_func never appears to be called. Any ideas? Thanks for the pointer as I was using this for a sample to work from, but as I mentioned the call back doesn't seem to occur?
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 1:28 pm    Post subject: Reply with quote

I've managed to get the call back correctly working, however i'm still getting an error with regard to write access to the server for caching the contents to 'Template_c'. This is not the desired effect I am after as i'm looking to store the entire cache in either the database/memcache. This is due to mirrored servers that have a delay and the cache will not be immediately updated between the various servers, therefore I assumed the cachehandler argument would alter writing to the filesystem and into the DB.

Whats the best way to implement this?
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 09, 2004 2:30 pm    Post subject: Reply with quote

you cannot handle *compiled templates* with cache_handler_func.
you can only handle *cached pages* with cache_handler_func.

there is a huge difference between the two.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 2:41 pm    Post subject: Reply with quote

messju wrote:
you cannot handle *compiled templates* with cache_handler_func.
you can only handle *cached pages* with cache_handler_func.

there is a huge difference between the two.


How would I go about rewriting this functionality, as i'd rather not rewrite the internals for simplicity sake.
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 09, 2004 2:49 pm    Post subject: Reply with quote

Andrew-J wrote:
How would I go about rewriting this functionality, as i'd rather not rewrite the internals for simplicity sake.


??? you want to know how to rewrite anything without rewriting it ???
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 2:57 pm    Post subject: Reply with quote

messju wrote:
Andrew-J wrote:
How would I go about rewriting this functionality, as i'd rather not rewrite the internals for simplicity sake.


??? you want to know how to rewrite anything without rewriting it ???


heh, no. I would like to know the simplist way to make smarty compile all templates/cache and any other IO functionality from a database than the filesystem. From what i'm understanding now is that I am going to have to alter many of the internal files, to call my own functions, which will essentially use memcache inplace of the filesystem.

As I mentioned I cannot use PHP to dynamically write files, thus the need to use memcache.
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 09, 2004 5:12 pm    Post subject: Reply with quote

Andrew-J wrote:
As I mentioned I cannot use PHP to dynamically write files, thus the need to use memcache.


are you sure you can't?

- the compiled templates can be created easily when the source-templates are available
- the compiled templates shouldn't change often: only when you roll-out new functionality on your site, not when content changes.
- each of your mirrored servers should be able to easily manage their own templates_c

if you really really don't want this you have other choices:

- rewrite large parts of smarty. (note: smarty heavily relies on the fact that it can include files from templates_c with include(). if you store your php-code *not* in the filesystem, you have to change that *and* you will loose the opportunity to use stock-versions TurckMMCache or APC or ZPS with your patched Smarty)

- compile the templates on a different host and upload templates_c to your mirrors. if you set $smarty->compile_check=false and smarty can find a compiled template for the template requested, then it won't try to write to templates_c, it would just read from it.

- dump smarty and use something else.

of course i would be very sad if you choose the last option, but i don't know your project, so i don't know how much smarty fits, and how much not.

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 9:27 pm    Post subject: Reply with quote

messju wrote:
Andrew-J wrote:
As I mentioned I cannot use PHP to dynamically write files, thus the need to use memcache.


are you sure you can't?

- the compiled templates can be created easily when the source-templates are available
- the compiled templates shouldn't change often: only when you roll-out new functionality on your site, not when content changes.
- each of your mirrored servers should be able to easily manage their own templates_c

if you really really don't want this you have other choices:

- rewrite large parts of smarty. (note: smarty heavily relies on the fact that it can include files from templates_c with include(). if you store your php-code *not* in the filesystem, you have to change that *and* you will loose the opportunity to use stock-versions TurckMMCache or APC or ZPS with your patched Smarty)

- compile the templates on a different host and upload templates_c to your mirrors. if you set $smarty->compile_check=false and smarty can find a compiled template for the template requested, then it won't try to write to templates_c, it would just read from it.

- dump smarty and use something else.

of course i would be very sad if you choose the last option, but i don't know your project, so i don't know how much smarty fits, and how much not.

greetings
messju


Thanks messju, that really helps. Firstly, I have no choice about the server configuration ultimately as this is a very large project. Atm, I have started hacking away at smarty's internals. This is not what I wish to do ultimately, however I need to get a front end rendered and completed for the task ahead of me.

The second option you mentioned sounds like a great method as I have two day deadline, and I would rather get on with other aspects. Are there any requirements as I would use a completely different server to attempt this?
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


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

PostPosted: Tue Nov 09, 2004 9:54 pm    Post subject: Reply with quote

Here's an idea that you may be able to sell: put templates_c on a private ram disk. You won't get faster and it is very safe.

I have another suggestion (which I think may be a worthwhile proposal for Smarty):

- implement a user stream wrapper
- implement a new class property, say fs_stream_prefix which will be prepended to "normal" filenames and matches your user stream wrapper
- modify all existing file access in Smarty (which, while in several places, is general modularized) where it wants to read/write from templates_c so that the fs_stream_prefix is prepended to the file name.

There you go, you get filesystem transparency and swappable back-ends at the cost of having to use a user-land stream wrapper. Implement your custom stream handler in a PHP module for extra performance.


Last edited by boots on Tue Nov 09, 2004 10:50 pm; edited 1 time in total
Back to top
View user's profile Send private message
Andrew-J
Smarty Rookie


Joined: 09 Nov 2004
Posts: 8
Location: London

PostPosted: Tue Nov 09, 2004 10:07 pm    Post subject: Reply with quote

boots wrote:
Here's an idea that you may be able to sell: put templates_c on a private ram disk. You won't get faster and it is very safe.

This is still not viable, I do not manage the server and a simple request to add forcetype on particular files was refused. So, I am assuming creating a private ram disk is out of the question;).

boots wrote:
Implement your custom stream handler in a PHP module.

Great suggestion. That never even crossed my mind, however I have used a generic class that allows you to select the handling for compiling templates. Anyway thanks for the pointers...
_________________
Andrew Johnstone
www.ajohnstone.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Nov 10, 2004 9:52 am    Post subject: Reply with quote

Andrew-J wrote:
The second option you mentioned sounds like a great method as I have two day deadline, and I would rather get on with other aspects. Are there any requirements as I would use a completely different server to attempt this?


you should just use the same version of php. it doesn't have to be the same minor version, but there are very few things, that smarty may compile differently when running under php5 than under php4.

one thing you have to keep in mind is, that such a setup (compiling on a different host) is not heavily tested by the community as a "normal" setup is. but in principle the compiled templates should be portable when you use identical versions of smarty on both ends.
Back to top
View user's profile Send private message Send e-mail 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 -> Installation and Setup 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