Severity: 8192
Message: Methods with the same name as their class will not be constructors in a future version of PHP; Cacheall_info has a deprecated constructor
Filename: libraries/cacheall_info.php
Line Number: 136
<?php
require_once ("path_to_begin_caching.php/begin_caching.php");
//your php code
require_once ("path_to_end_caching.php/begin_caching.php");
?>
<?php
require_once("begin_cache.php");
require_once($_REQUEST["p"]);
require_once("end_cache.php");
?>
<?php
/* begin_cache.php
* programmer RvH date 09-11-2013
*/
if ($_SERVER['REQUEST_METHOD'] === 'GET') // Only process get REQUESTS
{
$cachedir_bc = '/path/to/your/cache/'; // Directory to cache files in (keep outside web root)
$extension_bc = '.htm'; // DOT + Extension to give cached files (usually .cache, .htm, .txt)
$exclude_bc = '__'; // Don't cache files with these markers ( caches t_est_.php but not tes__t.php )
$key_bc = "s3crEt";
$cachetime_bc = 86400; // cache is valid: time in seconds 60*60*24 = 86400 = 1 day
$page_bc = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
error_reporting(0); // expensive
ignore_user_abort(TRUE); // make sure the cachefile gets written to disk
$ignore_list_bc = array( // files not to be cached = ignore list
'counter.php',
'search.php',
);
if (strpos($page_bc,$exclude_bc) !== false ) // add files with markers to the ignore list
$ignore_list_bc[] = $page_bc;
$cachefile_bc = $cachedir_bc . md5($page_bc) . $extension_bc; // Cache file to either load or create
$ignore_page_bc = false;
if( in_array($page_bc,$ignore_list_bc) ) // do we need to ignore this file
$ignore_page_bc = true; // if a match was found set it to true
if ( isset($_SERVER['REQUEST_TIME']) ) // not always available, but if so faster dan time()
$now_bc = $_SERVER['REQUEST_TIME'];
else
$now_bc = time();
// caching
if ($ignore_page_bc === false) // not in ignore list than proceed
{
if (is_file($cachefile_bc)) // do we have one
{
$filesize_bc = filesize($cachefile_bc);
$last_modified_bc = filemtime($cachefile_bc);
$etag_bc = md5_file($cachefile_bc);
clearstatcache();
header_remove ("Pragma"); // sometimes hosting sets Pragma no-cache
header_remove ("Expires");
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_bc)." GMT");
header("Etag: $etag_bc");
header ("Cache-Control: must-REVALIDATE");
// serve from browser cache just send headers
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_bc || trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag_bc )
{
header("Warning: BROWSER cache size $filesize_bc");
header("HTTP/1.1 304 Not Modified");
ob_end_clean();
exit;
}
// serve from cache if still valid
if ($now_bc - $cachetime_bc < $last_modified_bc)
{
$size_bc = filesize($cachefile_bc);
header("Content-Encoding: gzip");
header("Expires: $cachetime_bc");
header("Warning: 200 VALID from cache filesize $filesize_bc");
if (readfile($cachefile_bc)){
ob_end_clean();
exit();
}
}
// expired cache
$fp_bc = fopen( $cachefile_bc, "ab"); // Let's first try to lock (w or w+ would erase the file)
if (! flock($fp_bc, LOCK_EX | LOCK_NB)) // lock but don't wait for it, if we can't get one
{ // can't lock, SERVE AN OLD CACHEFILE
ob_start();
header("Content-Encoding: gzip");
header("Content-Length: ".$filesize_bc);
header("Expires: $cachetime_bc");
header("Warning: 200 EXPIRED cache");
header("Etag: ".$etag_bc);
if (fpassthru($fp_bc))
{
fclose($fp_bc);
ob_end_clean();
exit();
}
}
else
flock($fp_bc, LOCK_EX); // lock it (wait) and create new cachefile
}// eof cachefile exists
else
{
$fp_bc = fopen( $cachefile_bc, "ab"); // No cachefile at all, let's first try to lock ( w or w+ would erase the file)
flock($fp_bc, LOCK_EX); // lock and wait for it than create new cachefile
}
ob_start();
}// eof ignore page
}// eof GET
<?php
/* end_cache.php
* programmer RvH date 09-11-2013
*/
if ( ! isset( $key_bc ) || $key_bc !== "s3crEt") // if someone forgets to put this outside webspace
{
ob_end_clean();
@fclose($fp_bc);
@unlink($cachefile_bc);
die("No direct acces allowed");
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') // ignore post!
{
if ($ignore_page_bc === false) // not in ignore list than proceed
{
ftruncate($fp_bc, 0); // same as fopen with w
$contents_bc = ob_get_contents();
$filesize_bc = ob_get_length();
ob_end_clean();
if( stripos($contents_bc,"<pre>") === false ) // not to be used with <pre> tags
$contents_bc = sanitize_output($contents_bc);
$compressed_out_bc = gzencode($contents_bc,9);
header("Content-Encoding: gzip");
header("Warning: 200 cache CREATED $filesize_bc bytes time = ".date("Y-m-dTH:i:s",$now_bc));
header("Cache-Control: must-revalidate");
header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $now_bc));
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', $now_bc + $cachetime_bc));
header("Etag: ".$etag);
fwrite($fp_bc, $compressed_out_bc); // save the contents of output buffer to the file
flock($fp_bc, LOCK_UN);
fclose($fp_bc);
echo"$compressed_out_bc";
exit();
}
}
function sanitize_output($buffer)
{
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
<?php
$cachedir_bc = ""; // the directory where the cachefiles are
$cachetime_bc = ""; // the time the cachefiles stay valid
$cachedir_bc .= ( substr($cachepath, -1) !== "/" ) ? "/" : "";
$files = array_diff( scandir(), array("..", ".",".htaccess","index.html") ); // skip these
foreach($files as $file)
if ( time() - $cachetime_bc > filemtime($cachedir_bc.$file) ) // delete cachefiles if they are too old
@unlink($cachedir_bc.$file);
?>