-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear_cache.php
100 lines (93 loc) · 2.31 KB
/
clear_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
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
<?php
$result = '';
$b_result='';
$file_cache = '/tmp/cache-object-ninhmy/result';
if(@file_exists($file_cache)) {
$b_result = file_get_contents($file_cache);
$result = $b_result;
} else {
@mkdir('/tmp/cache-object-ninhmy/', 0777);
}
//
function str_contain($haystack, $needle) {
$result = strpos($haystack, $needle);
if(strlen($result.'') > 0 && $result*1 >= 0 ) {
return true;
} else {
return false;
}
}
// /gxninhmy/
function initCacheDir() {
if(!isset($GLOBALS['cachedir'])) {
$GLOBALS['cachedir'] = '/tmp/cache-ninhmy/';
}
}
//
function clear_all_cache() {
initCacheDir();
//
$cachedir = $GLOBALS['cachedir'];
if(strlen($cachedir) > 0) {
global $result;
$result = $result . '<br> clear all at: '.date("d/m/Y h:i:s A", time()).' ';
$files = glob($cachedir.'*'); // get all file names
foreach($files as $file){ // iterate files
clear_cache($file, false); // delete file
}
}
}
function get_file_name($link) {
echo '<div>get_file_name: '.$link . '</div>';
return md5($link) . '.cache';
}
function clear_cache($file='', $isInfo=true) {
if(strlen($file) > 0) {
initCacheDir();
//
$cachedir = $GLOBALS['cachedir'];
if(!str_contain($file, $cachedir) > 0) {
$file = $cachedir.$file;
}
echo '<div>clear_cache: '.$file . '</div>';
if(is_file($file)) {
@unlink($file);
//
if($isInfo) {
global $result;
$result = $result . '<br> clear file: '.$file.' at: '.date("d/m/Y h:i:s A", time()).' ';
}
}
}
}
if(isset($_REQUEST['clear'])) {
$clear = $_REQUEST['clear'];
if(strlen($clear) > 0) {
if($clear === 'all') {
clear_all_cache();
} else if($clear === 'home') {
$domain= $_SERVER['HTTP_HOST'];
clear_cache(get_file_name('http://' . $domain));
clear_cache(get_file_name('http://' . $domain.'/'));
} else {
$domain= $_SERVER['HTTP_HOST'];
if(!str_contain($clear, $domain)) {
$clear = 'http://' . $domain . $clear;
}
clear_cache(get_file_name($clear));
}
}
}
if($b_result != $result) {
$fp = @fopen($file_cache, 'w');
@fwrite($fp, $result);
@fclose($fp);
@chmod($file_cache, 0755);
}
if(isset($_REQUEST['info'])) {
$info = $_REQUEST['info'];
if(strlen($info) > 0 && $info === 'true') {
echo '<div>'.$result . '</div>';
}
}
?>