Welcome to Geeklog Thursday, November 21 2019 @ 05:54 am EST

Geeklog Forums

Caching Template Library


Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/05
Posts: 985
There will be a new file in the hacks download area. It contains a drop-in replacement for the existing template library used by Geeklog that is faster. There are several issues though so don't just install it. You will need to test your website out a bit as there are some issues. All the issues are spelled out in the readme file included in the archive. Here are some excerpts from that file:

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

  • Multi-root: Templates can be created with more than one root directory. When searching for a file the library will look in each root directory until it finds the file.
  • Automatic Language variables: Template variables in the form {$LANG_xxx[yyy]} will automatically substitute without a call to set_var().
  • PHP code runs in templates
  • Automatic urlencode/htmlspecialchars: A call to the listed function can be automatically be added by adding :u or :s to the {variable:u}

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

  • There should probably be a way to clear the cache built-in to Geeklog.
  • When a plugin is disabled/deleted, its cache files should go away.
  • The geeklog installer page should wipe out the cache directory as part of any install or upgrade.

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

 Quote

Status: offline

mevans

Forum User
Full Member
Registered: 08/02/04
Posts: 393
Location:Texas
Joe has done an excellent job with this library and from my testing and benchmarking, it does improve the overall performance of a Geeklog site. You can see some of my test results here.

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
 Quote

All times are EST. The time is now 05:54 am.

  • 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