-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_cache.php
50 lines (35 loc) · 1.1 KB
/
index_cache.php
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
<?php
require 'vendor/autoload.php';
Predis\Autoloader::register();
$h_parent = md5($_SERVER['HTTP_HOST']); //Domain used as primary key
$h_path = md5($_SERVER[REQUEST_URI]); //Requested URI used as field
$expireTime = strtotime("+72 hours"); //Expiration time, measured in Unixtime stamp from moment key is set.
$predis_config = array('host'=>'127.0.0.1','password'=>"3.9OmMak&a4!");
//Connecting to Redis
session_start();
if (!$_SESSION["predicon"]){
$_SESSION["predicon"] = new Predis\Client($predis_config);
}
$redis = $_SESSION["predicon"];
//end
//Get New Contents
function get_page_content(){
ob_start();
require 'index.php';
$contents = ob_get_contents();
ob_end_clean();
return str_replace("/index_cache.php",'',$contents);
}
//End
//No Cache Request
if($_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache'){
echo get_page_content();
}
//Getting Cache and Setting Cache
if (!$redis->hexists($h_parent,$h_path))
{
$redis->hset($h_parent,$h_path,get_page_content());
$redis->expireat($h_parent,$expireTime);
}
echo $redis->hget($h_parent,$h_path);
?>