Project

General

Profile

1 38716 eri.katsar
<?php
2
require_once('./js/log4php/Logger.php');
3
require_once('./paths.php');
4
require_once('./MYDB.php');
5
6
class cleanCache {
7
	private $log;
8
	private $cache = null; //predis
9
10
public function __construct(){
11
12
		global $redis_host;
13
		global $redis_port;
14
		global $redis_scheme;
15
		global $host;
16
17
18
               $this->log = Logger::getLogger("cleanCache");
19
               Logger::configure('./js/log4php/log4php.xml');
20
21
             if(class_exists("Predis\Client")){
22
23
                        try {
24
//todo changed timeout from 0 to -1
25
                        $this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
26
                                $this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
27
                        } catch(Exception $e) {
28
                                $this->log->error("Error connecting to Redis server: ".$e->getMessage());
29
                                $this->cache = null;
30
                        }
31
                }
32
        else{
33
            $this->log->info("cache does not exist"); //predis
34
                        exit;
35
        }
36
37
38
	}
39
public function cleanUp()
40
{
41
42
$keys = $this->cache->keys("*");
43
44
for($x=0;$x<count($keys);$x++) {
45
if (strpos($keys[$x],'STATS')===false)
46
{
47
try
48
{
49
$pers=$this->cache->hget($keys[$x],'persistent');
50
//$this->log->info("id : ".$keys[$x]);
51
//$this->log->info("persistent : ".$pers);
52
53
if($pers=="false"||($pers=='0'))
54
{
55
$this->log->info("removing id : ".$keys[$x]);
56
$this->cache->del($keys[$x]);
57
}
58
}
59
catch(Exception $e)
60
{$this->log->error('Error : '.$e->getMessage());}
61
62
}
63
else
64
{ $this->log->info("Ignoring chart key: ".$keys[$x]); }
65
66
}
67
$this->cache->quit();
68
$this->log->info("Done cleaning Cache Up! ");
69
70
}
71
72
}
73
//$rc = new cleanCache();
74
//$rc->cleanUp();
75
?>