Menu

#10 Speed Boost: Smarty cache of files + gzip output buffering

open
nobody
None
5
2005-08-08
2005-08-08
wookie
No

phpAutoGallery would get a real *BOOST* in speed if
smarty caching is implemented. I made a small hack on
the wrapper.php as proof of concept, however to make it
really cool it would need to be implemented with
consideration of changing photo sources.. (ie make a
hash id of the photo directories, if the hash changes
clear the cache)

Also it would be nice (but not that necessary) to gzip
the output using ob_start("ob_gzhandler"), most modern
browsers support gzip encoding.

My little Mod in wrapper.php for smarty cache below:

<snippet>
...
// init smarty object, settings
$template = new Smarty;
$template->template_dir = './templates/' .
$cfg['which_template'] . '/';
if (!file_exists($cfg['tmp_path'] . 'phpAutoGallery/'
. $HTTP_SERVER_VARS['SERVER_NAME'] . '_smarty_compile/')) {
createTmpDirs($cfg['tmp_path'], 'phpAutoGallery/' .
$HTTP_SERVER_VARS['SERVER_NAME'] . '_smarty_compile/');
}
$template->compile_dir = $cfg['tmp_path'] .
'phpAutoGallery/' . $HTTP_SERVER_VARS['SERVER_NAME'] .
'_smarty_compile/';
$template->_file_perms = 0666;
$template->_dir_perms = 0777;
$oldumask = umask(0000);

// *cacheing* by wookie
if (!file_exists($cfg['tmp_path'] . 'phpAutoGallery/'
. $HTTP_SERVER_VARS['SERVER_NAME'] . '_smarty_cache/')) {
createTmpDirs($cfg['tmp_path'], 'phpAutoGallery/' .
$HTTP_SERVER_VARS['SERVER_NAME'] . '_smarty_cache/');
}
$template->cache_dir = $cfg['tmp_path'] .
'phpAutoGallery/' . $HTTP_SERVER_VARS['SERVER_NAME'] .
'_smarty_cache/';
$template->caching = true;
$template->cache_lifetime = -1;
$cacheID = md5($HTTP_SERVER_VARS["REQUEST_URI"]);
if(!$template->is_cached("index.tpl", $cacheID)) {
// get informations about where and who i am

......

(scroll down the page)
.......

} // end of pic view mode

}
}
// calculate processing time
$pt_end = getmicrotime();
$pt = sprintf("%0.4f", $pt_end - $pt_start);
$template->assign('vProcessingTime', $pt);

// display smarty template
$template->debugging = false;
$template->display('index.tpl',$cacheID);
....
</snippet>

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.