This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/includes/jpgraph/docs/chunkhtml/ch09s04.html
2011-05-28 19:51:52 +10:00

116 lines
9.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Using the cache with Client Side Image Maps (CSIM)</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch09.html" title="Chapter 9. Using the JpGraph cache system"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Using the cache with Client Side Image Maps (CSIM)</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 9. Using the JpGraph cache system</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Using the cache with Client Side Image Maps (CSIM)"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect1.cache-csim"></a>Using the cache with Client Side Image Maps (CSIM)</h2></div></div></div>
<p>(See <a class="xref" href="ch10.html" title="Chapter 10. Using CSIM (Client side image maps)">Chapter 10. <i>Using CSIM (Client side image maps)</i></a> for a full description on the usage of CSIM
together with the library)</p>
<p>You can also use the cache system for images that uses image maps (CSIM) as well.
The cache system interface is slightly different in this case since the cache needs
to store both the cached image and the cached image-map. It also needs to change due
to the added complexity with CSIM scripts not sending back an image but rather a
pre-formatted HTML page. The two major differences from the non-CSIM cache
is:</p>
<p>
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p>The cached version will <span class="bold"><strong>not</strong></span> be stored in the previous defined cache
directory. It uses a different cache directory.</p>
</li><li class="listitem">
<p>The script that want to make use of the cache system together with
CSIM must call an extra method, <code class="code">CheckCSIMCache()</code>, to check
the cache.</p>
</li></ol></div><p>
</p>
<p>
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>Please remember that when using CSIM you must end your script with a call
to <code class="code">Graph::StrokeCSIM()</code> method instead of the
<code class="code">Graph::Stroke()</code> used for non-CSIM. </p>
</div><p>
</p>
<p>To use the cache with CSIM you have to call the
<code class="code">Graph::CheckCSIMCache()</code>. As with the caching for non-CSIM you have
to supply a name to be used for the cached version (it can be manually or automatic)
as well as an optional timeout value. The default timeout value if nothing else is
specified is 60 minutes.</p>
<p>The name argument requires some more explanations. The file name must be specified
as a relative name. </p>
<p>For example "<code class="filename">myimage</code>" or perhaps
"<code class="filename">firstpage/image3</code>". </p>
<p>The reason for his is that a script that uses CSIM does not send back an image.
Instad it sends back a HTML page which includes the image map coordinates and has an
included "<span class="markup">&lt;img href=" ... "&gt;</span>" tag which references the image
script recursively in normal cases but if the image is found in the cache this
reference will be to a static image instead.</p>
<p>Depending on the installation of the library this will now end up in the directory
specified in the <code class="code">CSIMCACHE_DIR</code> define. This must also be a directory
accessible by the normal HTTP/PHP process. By default, if nothing else is specified,
a directory called "<code class="filename">csimcache</code>" will be created in the same
directory as the image script itself.</p>
<p>The default value has the drawback that the directory from where the script is
executed must also be writable by the process running PHP. Best practice here is to
keep the number of writable directory for PHP down to a minimum and re-use the same
directory as is used for the standard cache. </p>
<p>This however, requires that the PHP and HTTP setup is such that the cache
directory is also accessible by the HTTP server from the htdocs root.</p>
<p>The <code class="code">CheckCSIMCache()</code> method checks the cache for an existing cached
version and if found it returns it and halts execution of the script. So, this call
should be the first call after the creation of the core graph instance, i.e.
<code class="code">$graph = Graph($width,$height)</code> and before any heavy work is done to
create the image so that no unnecessary work is done in case a cached image + image
map is found.</p>
<p>The general structure of a script that uses CSIM and cache should follow the
template shown in </p>
<p>
</p><div class="example"><a name="id2535468"></a><p class="title"><b>Example 9.2. General structure for a CSIM script that uses CSIM</b></p><div class="example-contents">
<div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> ... any necessary includes</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$width</span><span class="hl-code"> = ...
</span><span class="hl-var">$height</span><span class="hl-code"> = ...
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">Graph</span><span class="hl-brackets">(</span><span class="hl-var">$width</span><span class="hl-code">,</span><span class="hl-var">$height</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Check cache and use a 10 min timeout</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">CheckCSIMCache</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">csim_image1</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> If a cached version exists, execution halts here</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> and the cached HTML image map is sent back</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> ... construct and format the graph</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> ... finally send back the image map HTML script</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">StrokeCSIM</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div>
</div></div><p><br class="example-break">
</p>
<p>Please note that it is not necessary to pass any argument to the final call of
StrokeCSIM()</p>
<p>
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>The CSIM caching works by storing two files in the cache directory. One
file being the image and the other file being the corresponding image map as
a pure HTML file. The HTML file will reference the static image.</p>
</div><p>
</p>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch09.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>