[pmwiki-users] HtmlCache, Internationalizazion, layout problem

Thomas Bley thbley at gmail.com
Wed Jul 19 09:13:21 CDT 2006


Hello,

Thanks have tried it.
The light skin has some calls to SetTmplDisplay which is calling 
NoCache. These calls are even made if there is not authentication.
The (un)serialize used in handlebrowse has no use (maybe had some in the 
past ?), but costs a lot of performance.
Also there are some calls like SetProperty($pagename, 'description', 
PSS('$1'), ' ')) done from MarkupToHTML(), SetProperty calls NoCache, 
this disables htmlCaching.
Looking at the cache files only the content of the pagename is getting 
cached, not the sidebar / header / footer.

Here is my HandleBrowse() enabling caching and compressing of the whole 
page:
It's only cached for 1 hour to get modifications of the sidebar / header 
/ footer, maybe there is a better way ?
Compression is enabled if the browser supports it and the page is bigger 
than 8k.

## handle display of a page
function HandleBrowse($pagename, $auth = 'read') {
  global $DefaultPageTextFmt, $PageNotFoundHeaderFmt, $HTTPHeaders,
    $EnableHTMLCache, $NoHTMLCache, $PageCacheFile, $LastModTime, 
$IsHTMLCached,
    $FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt;
  $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
  if (!$page) Abort('?cannot read $pagename');
  PCache($pagename,$page);
  if (PageExists($pagename)) $text = @$page['text'];
  else {
    SDV($DefaultPageTextFmt,'(:include $[{$SiteGroup}.PageNotFound]:)');
    $text = FmtPageName($DefaultPageTextFmt, $pagename);
    SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 404 Not Found');
    SDV($HTTPHeaders['status'], $PageNotFoundHeaderFmt);
  }
  $opt = array();
  SDV($PageRedirectFmt,"<p><i>($[redirected from] <a rel='nofollow'
    
href='{\$PageUrl}?action=edit'>{\$FullName}</a>)</i></p>\$HTMLVSpace\n");
  if (@!$_GET['from']) { $opt['redirect'] = 1; $PageRedirectFmt = ''; }
  else $PageRedirectFmt = FmtPageName($PageRedirectFmt, $_GET['from']);
 
  if (@$EnableHTMLCache && !$NoHTMLCache && $PageCacheFile && 
@filemtime($PageCacheFile) > $LastModTime && 
@filemtime($PageCacheFile)+3600 > time()) {
    $IsHTMLCached = 1;
    if (strpos("@".@$_SERVER["HTTP_ACCEPT_ENCODING"],"gzip") && 
file_exists($PageCacheFile.",gz")) {
      header("Content-Encoding: gzip");
      echo file_get_contents($PageCacheFile.",gz");
    } else {
      echo file_get_contents($PageCacheFile);
    }
    exit;
  } else {
    $IsHTMLCached = 0;
    $GLOBALS["out"] = "";

    $text = '(:groupheader:)'.@$text.'(:groupfooter:)';
    $FmtV['$PageText'] = MarkupToHTML($pagename, $text, $opt);
    SDV($HandleBrowseFmt,array(&$PageStartFmt, &$PageRedirectFmt, 
'$PageText', &$PageEndFmt));
    PrintFmt($pagename,$HandleBrowseFmt);
 
    if (@$EnableHTMLCache && !$NoHTMLCache && $PageCacheFile) {
      if ($fp = @fopen("$PageCacheFile,new", "x")) {
        fwrite($fp, "<!--cached-->".$GLOBALS["out"]);
        fclose($fp);
        @unlink($PageCacheFile);
        rename("$PageCacheFile,new", $PageCacheFile);
      }
      if (strlen($GLOBALS["out"])>8192 && 
!@ini_get("zlib.output_compression")) {
        $GLOBALS["out_gz"] = gzencode("<!--cached_gzip-->".$GLOBALS["out"]);

          if ($fp = @fopen("$PageCacheFile,new,gz", "x")) {
          fwrite($fp, $GLOBALS["out_gz"]);
          fclose($fp);
          @unlink($PageCacheFile.",gz");
          rename("$PageCacheFile,new,gz", $PageCacheFile.",gz");
        }
      }
    } 
    if (strpos("@".@$_SERVER["HTTP_ACCEPT_ENCODING"],"gzip") && 
isset($GLOBALS["out_gz"])) {
        header("Content-Encoding: gzip");
      echo $GLOBALS["out_gz"];
    } else {
      echo $GLOBALS["out"];
    }
  }
}


I also disabled NoCache(); in SetProperty()

In PrintFmt() I changed:
echo $x;
to:
$GLOBALS["out"] .= $x;

In PrintWikiPage() I changed:
echo MarkupToHTML($pagename,$page['text']);
to:
$GLOBALS["out"] .= MarkupToHTML($pagename,$page['text']);

bye
Thomas


Patrick R. Michaud wrote:
> On Wed, Jul 19, 2006 at 12:57:32AM +0200, Thomas Bley wrote:
>   
>> Thanks,
>>
>> What about using a page directive to enable/disable caching: (analog to 
>> "(:title blabla:)"):
>> (:url_cache time=3600:)
>>
>> This settings allows a page to be cached as Html. The cache file is used 
>> for 1 hour.
>> So each author can decide if the page is cached or not. Also a setting 
>> per Group may be possible.
>>     
>
> Authors (or else PmWiki) still need to be smart enough not to cache
> read-protected pages or pages that are somehow "dynamic".
>
> But if you want to try PmWiki's built-in caching (which already is
> smart enough to know how long to cache pages, and to not cache pages
> that depend on the visitor's identity or other timing items), then 
> try the following in config.php:
>
>     $PageCacheDir = 'cache.d';
>     $EnableHTMLCache = 1;
>
> It can also be done on a per-group or per-page basis in local
> customization files.
>
>   
>> This would be very good for pages that don't change very often, but get 
>> viewed very frequently by the users.
>> On my site there are ~60000 views per month and ~40000 go only to the 
>> first page (which has many includes). So if I cache it better, the whole 
>> machine speeds up.
>>     
>
> For whatever it's worth, the pmwiki.org site gets ~800,000 views
> per month with no caching.  (A "view" here is a request for a wiki
> page; i.e., it's exclusive of requests for uploads, css files,
> images, etc.)
>
> Pm
>
>
>   





More information about the pmwiki-users mailing list