/usr/share/php/Cache/Output.php is in php-cache 1.5.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | <?php
// +----------------------------------------------------------------------+
// | PEAR :: Cache |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |
// | Christian Stocker <chregu@phant.ch> |
// | Vinai Kopp <kopp@netzarbeiter.de> |
// +----------------------------------------------------------------------+
//
// $Id: Output.php 178289 2005-01-26 09:47:28Z dufuz $
require_once 'Cache.php';
/**
* Class to cache the output of a script using the output buffering functions
*
* Simple output cache. Some pages require lots of time to compute. Caching the
* output can increase the overall speed dramatically, especially if you use
* a Shared Memory storage container.
*
* As you can see in the example the usage is extemely simple. To cache a script
* simple put some few lines of code in front of your script and some at the end.
* A preferrable place for this are the auto_prepend and auto_append files (=> php.ini).
*
* Usage example:
*
* // place this somewhere in a central config file
* define(CACHE_STORAGE_CLASS, 'file');
* // file storage needs a dir to put the cache files
* define(CACHE_DIR, '/var/tmp/');
*
* // get a cache object
* $cache = new Cache_Output(CACHE_STORAGE_CLASS, array('cache_dir' => CACHE_DIR));
*
* // compute the unique handle.
* // if your script depends on Cookie and HTTP Post data as well
* // you should use:
* // $cache_handle = array(
* // 'file' => $REQUEST_URI,
* // 'post' => $HTTP_POST_VARS,
* // 'cookie' => $HTTP_COOKIE_VARS
* // );
* // But be warned, using all GET or POST Variables as a seed
* // can be used for a DOS attack. Calling http://www.example.com/example.php?whatever
* // where whatever is a random text might be used to flood your cache.
* $cache_handle = $cache->generateID($REQUEST_URI);
*
* // now the magic happens: if cached call die()
* // to end the time consumptiong script script execution and use the cached value!
* if ($content = $cache->start($cache_handle)) {
* print $content;
* print '<p>Cache hit</p>';
* die();
* }
*
* // time consumption script goes here.
*
* // store the output of the cache into the cache and print the output.
* print $cache->end();
* print "<p>Cache miss, stored using the ID '$id'.</p>";
*
* If you do not want to cache a whole page - no problem:
*
* if (!($content = $cache->start($cache_handle))) {
* // do the computation here
* print $cache->end()
* } else {
* print $content;
* }
*
* If you need an example script check the (auto_)prepend and (auto_)append
* files of my homepage:
*
* http://www.ulf-wendel.de/php/show_source.php?file=prepend
* http://www.ulf-wendel.de/php/show_source.php?file=append
*
* Don't know how to use it or you need profiling informations?`
* Ask Christian he was patient with me and he'll be so with your questions ;).
*
* Have fun!
*
* @authors Ulf Wendel <ulf.wendel@phpdoc.de>
* @version $ID: $
* @package Cache
* @access public
*/
class Cache_Output extends Cache
{
/**
* ID passed to start()
*
* @var string
* @see start(), end()
*/
var $output_id = '';
/**
* Group passed to start()
*
* @var string
* @see start(), end()
*/
var $output_group = '';
/**
* PEAR-Deconstructor
* Call deconstructor of parent
*/
function _Cache_Output()
{
$this->_Cache();
}
/**
* starts the output buffering and returns an empty string or returns the cached output from the cache.
*
* @param string dataset ID
* @param string cache group
* @return string
* @access public
*/
function start($id, $group = 'default')
{
if (!$this->caching) {
return '';
}
// this is already cached return it from the cache so that the user
// can use the cache content and stop script execution
if ($content = $this->get($id, $group)) {
return $content;
}
// remember some data to be able to fill the cache on calling end()
$this->output_id = $id;
$this->output_group = $group;
// WARNING: we need the output buffer - possible clashes
ob_start();
ob_implicit_flush(false);
return '';
} // end func start
/*
* Stores the content of the output buffer into the cache and returns the content.
*
* @param mixed lifetime of the cached data in seconds - 0 for endless. More formats available. see Container::getExpiresAbsolute()
* @param string additional userdefined data
* @return string cached output
* @access public
* @see endPrint(), endGet(), Container::getExpiresAbsolute()
*/
function end($expire = 0, $userdata = '')
{
$content = ob_get_contents();
ob_end_clean();
// store in the cache
if ($this->caching) {
$this->container->save($this->output_id, $content, $expire, $this->output_group, $userdata);
}
return $content;
} // end func end()
/**
* Stores the content of the output buffer into the cache and prints the content.
*
* @brother end()
*/
function endPrint($expire = 0, $userdata = '')
{
$this->printContent($this->end($expire, $userdata));
} // end func endPrint
/**
* Sends the data to the user.
* This is for compatibility with OutputCompression
*
* @param string
* @access public
*/
function printContent($content = '')
{
if ($content == '') {
$content = &$this->container->cachedata;
}
print $content;
}
/**
* Returns the content of the output buffer but does not store it into the cache.
*
* Use this method if the content of your script is markup (XML)
* that has to be parsed/converted (XSLT) before you can output
* and store it into the cache using save().
*
* @return string
* @access public
* @see endPrint(), end()
*/
function endGet()
{
$content = ob_get_contents();
ob_end_clean();
$this->output_id = '';
$this->output_group = '';
return $content;
} // end func endGet
} // end class output
?>
|