Showing
1 changed file
with
56 additions
and
0 deletions
1 | +<?php | ||
2 | + | ||
3 | +use Action\AbstractAction; | ||
4 | + | ||
5 | +class ToolsController extends AbstractAction | ||
6 | +{ | ||
7 | + //清缓存选项 | ||
8 | + public function indexAction(){ | ||
9 | + header("Content-type: text/html; charset=utf-8"); | ||
10 | + $html = '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">'. | ||
11 | + '<link href="//cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">'. | ||
12 | + '<div style="margin-left:20%"><br/><h2>清除Wap缓存</h2>'; | ||
13 | + | ||
14 | + $channels = array( | ||
15 | + '频道页(男生)' => 'http://yohobuy/', | ||
16 | + '频道页(女生)' => 'http://yohobuy/girls', | ||
17 | + '频道页(潮童)' => 'http://yohobuy/kids', | ||
18 | + '频道页(创意生活)' => 'http://yohobuy/lifestyle', | ||
19 | + ); | ||
20 | + | ||
21 | + $html.='<ul style="margin-top:20px">'; | ||
22 | + foreach ($channels as $name => $url) { | ||
23 | + $url = '/tools/cacheclear?key=' . $url; | ||
24 | + $html .= sprintf('<li style="font-size:15px;height:35px;"><a href="%s" target="_blank">%s</a></li>', $url, $name); | ||
25 | + } | ||
26 | + $html.='</ul></div>'; | ||
27 | + echo $html; | ||
28 | + } | ||
29 | + | ||
30 | + //清缓存 | ||
31 | + public function cacheclearAction(){ | ||
32 | + header("Content-type: text/html; charset=utf-8"); | ||
33 | + $key = $this->get('key'); | ||
34 | + | ||
35 | + $cache_dir = '/Data/local/nginx-1.8.0/ngx_cache'; | ||
36 | + $request_url = $key; | ||
37 | + $url_hash = md5($request_url); | ||
38 | + | ||
39 | + $dir1 = substr($url_hash,-1,1) . '/'; | ||
40 | + $dir2 = substr($url_hash,-3,2) . '/'; | ||
41 | + $cached_file = $cache_dir . $dir1 . $dir2 . $url_hash; | ||
42 | + | ||
43 | + if (is_file($cached_file)) { | ||
44 | + if (unlink($cached_file)) { | ||
45 | + echo $request_url . " 缓存清除成功!\n"; | ||
46 | + } else { | ||
47 | + echo $request_url . " 缓存清除失败!\n"; | ||
48 | + } | ||
49 | + echo 'ok'; | ||
50 | + } else { | ||
51 | + echo $request_url . " 未被缓存!\n"; | ||
52 | + } | ||
53 | + } | ||
54 | +} | ||
55 | + | ||
56 | +?> |
-
Please register or login to post a comment