View previous topic :: View next topic |
Author |
Message |
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 12:36 am Post subject: Caching Smarty with a DB & Memcache. |
|
|
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? _________________ Andrew Johnstone
www.ajohnstone.com |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Nov 09, 2004 1:16 am Post subject: |
|
|
What kind of problems?
There is a Turck MMCache implementation in this thread that may give you some tips. |
|
Back to top |
|
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 10:19 am Post subject: |
|
|
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 |
|
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 1:28 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Nov 09, 2004 2:30 pm Post subject: |
|
|
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 |
|
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 2:41 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Nov 09, 2004 2:49 pm Post subject: |
|
|
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 |
|
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 2:57 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Nov 09, 2004 5:12 pm Post subject: |
|
|
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 |
|
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 9:27 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Nov 09, 2004 9:54 pm Post subject: |
|
|
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 |
|
Andrew-J Smarty Rookie
Joined: 09 Nov 2004 Posts: 8 Location: London
|
Posted: Tue Nov 09, 2004 10:07 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Nov 10, 2004 9:52 am Post subject: |
|
|
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 |
|
|