Triki Wiki / 2016-06-18 11:39:40
The Wiki that you are currently reading is an instance of the Triki Wiki by Tim Reeves (details). Triki Wiki is a nice, simple, elegant, file-based, PHP-implemented Wiki, perfect to run on a A1200. It installed nicely, just unzip its archive and set some parameters in the file config.php. It requires some fine-tuning when installing the FCKEditor v2.6.6 and improving its visual display: all fun in PHP .
I recently implemented an extension for Triki Wiki, which makes it easy to implement such extensions! , to cache the HTML pages generated from the Wiki pages. This extension greatly speeds up the serving of the pages. Below, I explain my extension, which source code is freely available here.
plugin-db-cache.php
Source Code |
Comments |
require("default-db.php");
function isNodeInCache($title) {
global $nodedir;
// blacklist the title
if (blacklistTitle($title)) {
return false;
}
$wikiFile = $nodedir.$title.".wiki";
$cacheFile = $nodedir.$title.".cache";
if (file_exists($wikiFile) &&
file_exists($cacheFile) &&
filemtime($wikiFile) < filemtime($cacheFile)) {
return TRUE;
}
return FALSE;
}
function saveNodeContentsInCache($title, $node) {
global $nodedir;
// open the file
$file = fopen($nodedir.$title.".cache", "w");
if ($file === false) return false;
// and lock it
flock($file, LOCK_EX);
// write content
fwrite($file, $node);
// finish
flock($file, LOCK_UN);
}
function getNodeContentsFromCache($title) {
global $nodedir;
if (!isNodeInCache($title)) return false;
// open the file
$file = fopen($nodedir.$title.".cache", "r");
if ($file === false) return false;
// and lock it
flock($file, LOCK_SH);
// read content
$html = fread($file, 65535);
$html = rtrim($html);
// finish
flock($file, LOCK_UN);
fclose($file);
return $html;
} |
|
|