static file caching
This commit is contained in:
parent
8e4d6583f5
commit
bdcca24f8d
@ -718,4 +718,42 @@ function _get_user() {
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _start_cache() {
|
||||||
|
$_do_cache = (CACHE && !isset($_COOKIE["shm_session"]) && !isset($_COOKIE["shm_nocache"]));
|
||||||
|
if($_do_cache) {
|
||||||
|
$hash = md5($_SERVER["QUERY_STRING"]);
|
||||||
|
$ab = substr($hash, 0, 2);
|
||||||
|
$cd = substr($hash, 2, 2);
|
||||||
|
$cachename = "data/$ab/$cd/$hash";
|
||||||
|
if(!file_exists("data/$ab/$cd/")) {
|
||||||
|
mkdir("data/$ab/$cd/", 0750, true);
|
||||||
|
}
|
||||||
|
if(file_exists($cachename)) {
|
||||||
|
$gmdate_mod = gmdate('D, d M Y H:i:s', filemtime($cachename)) . ' GMT';
|
||||||
|
|
||||||
|
if(isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
|
||||||
|
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"]);
|
||||||
|
|
||||||
|
if($if_modified_since == $gmdate_mod) {
|
||||||
|
header("HTTP/1.0 304 Not Modified");
|
||||||
|
header("Content-type: text/html");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header("Content-type: text/html");
|
||||||
|
header("Last-Modified: $gmdate_mod");
|
||||||
|
print file_get_contents($cachename);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
ob_start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _end_cache() {
|
||||||
|
$_do_cache = (CACHE && !isset($_COOKIE["shm_session"]) && !isset($_COOKIE["shm_nocache"]));
|
||||||
|
if($_do_cache) {
|
||||||
|
file_put_contents($cachename, ob_get_contents());
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
// set up and purify the environment
|
// set up and purify the environment
|
||||||
define("DEBUG", true);
|
define("DEBUG", true);
|
||||||
|
define("CACHE", true);
|
||||||
define("SCORE_VERSION", 's2hack');
|
define("SCORE_VERSION", 's2hack');
|
||||||
define("VERSION", 'trunk');
|
define("VERSION", 'trunk');
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ if(!file_exists("config.php")) {
|
|||||||
require_once "core/util.inc.php";
|
require_once "core/util.inc.php";
|
||||||
_version_check();
|
_version_check();
|
||||||
_sanitise_environment();
|
_sanitise_environment();
|
||||||
|
_start_cache();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// load base files
|
// load base files
|
||||||
@ -125,6 +126,8 @@ try {
|
|||||||
if($database->engine->name != "sqlite") {
|
if($database->engine->name != "sqlite") {
|
||||||
$database->db->CommitTrans(true);
|
$database->db->CommitTrans(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end_cache();
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
catch(Exception $e) {
|
||||||
$version = VERSION;
|
$version = VERSION;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user