Plugin: Static Cache Control, ZP on steroids?

After working on HTTP Cache Control for ZP, I decided to try to bypass PHP processing altogether in an attempt to make ZP run as fast and light as a static website. I think I succeeded, albeit not in the most elegant manner. ^_^

http://www.tummblr.com/my-code/zenphoto-plugin-static-cache-control/

"staticCacheControl is a plugin that caches (and optionally gzips) Zenphoto pages on the file system to minimize PHP execution, making your dynamic image gallery run as fast and light on resources as a static website.

No matter how well you optimize PHP processing through code optimizations, opcode and database query caching, a dynamic PHP application still can't beat the performance (speed/time, CPU/memory usage) of a website with the same content displayed using static HTML files. However, good luck updating thousands of static HTML pages by hand. :P With staticCacheControl, you can have the best of both worlds.

staticCacheControl automates the process of generating static HTML copies of your Zenphoto pages, redirecting visitors to these cached pages when possible, and also the validating/refreshing of the static cache when your Zenphoto pages change. Thus, you can enjoy the performance of static pages without the hassle of updating them manually.

This plugin is designed for use in the album.php, albumarchive.php, image.php, index.php of your theme. It can be used in conjunction with (after) httpCacheControl for optimal results."

I wonder if I've gone overboard with my attempts at optimizing Zenphoto's performance since ZP's quite snappy on its own. :P Oh well, I learned a LOT doing this.

Comments

  • staticCacheControl now supports comments.
  • tummblr, you should create a ticket in trac if you are going to be modifying the zp-core. It looks like this is definitely something that should be integrated in the distribution if you do not mind?!
  • I'd be very happy if this feature made it into Zenphoto. Before that happens though, I hope that the programming guru's around here can inspect the code and design. staticCacheControl and httpCacheControl are untested on a live site (waiting for a slice from Slicehost grrr), and I'm a newbish coder.

    I'll make a Trac ticket in a bit.

    Right now, all the code resides in static_cache_control.php, and you just need to include and execute 1 function in your theme file. No zp-core modifications are necessary yet, so please give it a whirl! :)
  • to tummblr:
    can you help me please, what am I doing wrong?
    I added to index.php your code:
    include_once('zp-core/static_cache_control.php');
    // get $mtime from other function/code, ex.
    // $mtime = httpCacheControl(__FILE__);
    // also enable gzip of cached files
    staticCacheControl(__FILE__, $mtime, true);

    But I got the error:
    Fatal error: Call to undefined function: in_context() in /home/my_user_folder/public_html/zenphoto/zp-core/static_cache_control.php on line 290
  • The code should be inserted in your theme files, not index.php in Zenphoto's root. For example, using the "default" theme:

    Place static_cache_control.php in /zenphoto/themes/default
    Insert at the top of /zenphoto/themes/default/index.php
    `include_once('static_cache_control.php');

    staticCacheControl(__FILE__);`

    You can't call the function with $mtime if you don't already have that value from somewhere else. If you omit the second parameter, staticCacheControl() will attempt to calculate it.
  • Thanks for your help, it works! You've done great job!
  • Hi All!
    I have trouble with this plugin on my site: http://wallpaperstock.eu
    index and album pages are ok, but on image page I have the same pictures.
    maybe my theme is outdated or this is a bug?

    Thanks for your help!
  • acrylian Administrator, Developer
    The static cache control this thread is actually about is not the same as the static-html-cache plugin. The first one is found here on our "hacks" page: http://www.zenphoto.org/2008/06/performance-hacks. I never tried that hack and have not tested it with the static html cache plugin. If you use both together that could be the reason.
  • sorry for bad topic, i´m using just the "static-html-cache" plugin provided by zenphoto (svn2869).
    Thanks for your reply!
  • acrylian Administrator, Developer
    Alright, just wanted to be sure about the issue. Thanks for the ticket.

    Actually I don't see why that plugin in should have this weird effect nor did I ever noticed that. Are the permissions correctly set on the cache_html folder? Did you clear the cache_html folder?
  • cache_html and subfolders have permission 777, cache files have 606.
    Yes, i cleared the cache_html folder.
  • in cache_html/images folder are cache filenames without image filenames, for example:
    `Celebrities_Cameron Diaz-_en_US.html` so it looks like files in cache_html/albums folder.
  • acrylian Administrator, Developer
    I could reproduce it and found the error, a small typo... So it will be fixed in tonight's nightly.
  • thanks for your quick patch, now its work great, but search pages are empty /are cached/
  • I would love to use this plugin, but the link in the first post is dead. Does it still exist? Could anyone re-upload it so others can continue to use it? :)
  • acrylian Administrator, Developer
    Sorry, there is this old ticket where you can download a file: http://www.zenphoto.org/trac/ticket/318

    Note that this is not supported and may not work with the current Zenphoto version. There is also a static cache plugin available btw.
Sign In or Register to comment.