Tools.php
1.88 KB
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
<?php
use Action\AbstractAction;
class ToolsController extends AbstractAction
{
//清缓存选项
public function indexAction(){
header("Content-type: text/html; charset=utf-8");
$html = '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">'.
'<link href="//cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">'.
'<div style="margin-left:20%"><br/><h2>清除Wap缓存</h2>';
$channels = array(
'频道页(男生)' => 'http://yohobuy/',
'频道页(女生)' => 'http://yohobuy/girls',
'频道页(潮童)' => 'http://yohobuy/kids',
'频道页(创意生活)' => 'http://yohobuy/lifestyle',
);
$html.='<ul style="margin-top:20px">';
foreach ($channels as $name => $url) {
$url = '/tools/cacheclear?key=' . $url;
$html .= sprintf('<li style="font-size:15px;height:35px;"><a href="%s" target="_blank">%s</a></li>', $url, $name);
}
$html.='</ul></div>';
echo $html;
}
//清缓存
public function cacheclearAction(){
header("Content-type: text/html; charset=utf-8");
$key = $this->get('key');
$cache_dir = '/Data/local/nginx-1.8.0/ngx_cache';
$request_url = $key;
$url_hash = md5($request_url);
$dir1 = substr($url_hash,-1,1) . '/';
$dir2 = substr($url_hash,-3,2) . '/';
$cached_file = $cache_dir . $dir1 . $dir2 . $url_hash;
if (is_file($cached_file)) {
if (unlink($cached_file)) {
echo $request_url . " 缓存清除成功!\n";
} else {
echo $request_url . " 缓存清除失败!\n";
}
echo 'ok';
} else {
echo $request_url . " 未被缓存!\n";
}
}
}
?>