Welcome to Geeklog, Anonymous Thursday, November 21 2024 @ 02:30 pm EST
Geeklog Forums
Caching Template Library
jmucchiello
Background
PHP was created so people could create websites by mixing code right in the HTML. When designers decided that mixing business logic with presentation was a bad thing, rather than using disciplined coding techniques to avoid that pitfall, the template library was born. So, an interpreted language designed to create HTML was being used to interpret template files to make HTML.
This hack attempts to make templates faster by turning them back into PHP. The existing templates are converted into working PHP code and stored in a cached directory. "Running" the template becomes as easy as "include"ing the cached file.
Goals
- Drop-in replacement for existing template class
- Require minimal modifications to Geeklog and its plugins
- Executes faster that the original library
Post Install Notesu]
That's almost it. The aim was to minimize the impact on core code. That was done
but minimize doesn't mean no codes are needed. There are some places in the core
code (and in many plugins) where a buggy feature of the old template library was
being taken advantage of.
Basically, the new lib replaces template variables by turning them into php code
that is executed. This is fast but it also can run afoul of sloppy coding. There
are several places in core Geeklog where template variables are set AFTER the
call to parse(). This is a bug based on the way the library is supposed to work
but since the variable remains in the text stream, it get replaced during the
final parse. This library isn't as forgiving. Basically, some lines of code need
to be reordered so the library will produce the "expected" output.
The author of MediaGallery helped me clean up this code in his plugin and he
found many bugs in MG that will be fixed in its next release. So while this
library is not compatible with MG at the moment, it will be with the next
release of MG. Mark is running this library on his live gllabs.org site so by
now the new template class should be pretty solid.
One forum issue is noted below but there are probably other issues. And I have
not gone around fixing all the other plugins that may suffer from these bugs. I
don't advise using this library on your live webpage unless you are able to find
these kinds of bugs and fix them.
The easiest fix for screens that don't look right is to set $_CONF[] to false.
This turns off the new library completely. The next easiest method is to replace
the "new Template" to a call to COM_newTemplate() setting $use_old_class to
true:
$T = new Template('.../some/root/path');
becomes:
$T = COM_newTemplate('.../some/root/path', 'remove', true);
What's the point of this hack? Well, I want it out there. Hopefully it will
become part of Geeklog core in the future.
Additional Features
Troubleshooting
The most common problem you will run into with the caching templates is
forgetting they are there. If you go into a thtml file and make a change and it
isn't showing up. You may need to go delete the cached file as the algorithm to
overwrite them only works when the file dates are correct. Some ftp systems and
web consoles screw up the file times of uploaded files preventing the class from
updating the cached php file.
TODO
Author
Joe Mucchiello can be contacted by email: joe at throwingdice dot com
Original PHPLIB documentation can be found using your favorite web search engine.
Thanks to Michael Jervis for doing some permformance checks on the proof-of-
concept version of this library showing that it was faster than the base
library. Without that I never would have spent the time polishing this library.
Thanks to Mark R. Evans for really helping shake out the bugs, doing performance
checks, and for basically beta testing the library on his live website:
http://www.gllabs.org
mevans
As Joe stated, Media Gallery v1.5.0 and below do not work with this caching library. It does not allow variables to be assigned after the page has been parsed like the stock library and unfortunately, I had a few places in Media Gallery where I was a little sloppy and did just that. The next release will resolve these issues.
Overall, it has made a definite improvement in performance at gllabs.org. Good work Joe!
Thanks!
Mark
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content