1 | <?php |
---|
2 | /** |
---|
3 | * Wipe-Cache is a small cache wiping application for online usage. |
---|
4 | * For convenience it is displayed in the style of the website |
---|
5 | **/ |
---|
6 | $seiten_id = 'wipe-cache'; |
---|
7 | $version = '$Id$'; |
---|
8 | $titel = 'Wipe Cache'; |
---|
9 | $dynamischer_inhalt = true; |
---|
10 | |
---|
11 | require "technikum29.php"; |
---|
12 | ?> |
---|
13 | <h2>Cache leeren</h2> |
---|
14 | |
---|
15 | <?php |
---|
16 | |
---|
17 | if(isset($_GET['wipe'])) { |
---|
18 | print "<h3>Cache-Leerung</h3>"; |
---|
19 | rrmdir_sub($cache_dir); |
---|
20 | print "Fertig"; |
---|
21 | print "<h3>Erneut Cache leeren?</h3>"; |
---|
22 | } |
---|
23 | ?> |
---|
24 | |
---|
25 | <p>Auf diesem Server (<?php echo $_SERVER['SERVER_NAME']; ?>) sind im Verzeichnis |
---|
26 | <tt><?=$cache_dir ?></tt> derzeit <b><?php echo getFileCount($cache_dir); ?> Dateien</b> |
---|
27 | gecacht.</p> |
---|
28 | |
---|
29 | <form method="get"> |
---|
30 | <input type="submit" value="Cache leeren" name="wipe"> |
---|
31 | <input type="submit" value="Anzeige aktualisieren" name="just-aktualisieren"> |
---|
32 | </form> |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | <h3>Zum Cache-System</h3> |
---|
37 | |
---|
38 | <p>Die technikum29-Website wird seit Version 6 mit PHP und einem mehrstufigen |
---|
39 | Cache-System unterstützt, sodass Seiten nur bei Änderungen gecacht werden müssen. |
---|
40 | Zur Verfikation, ob der Cache einer Seite invalide ist, werden dabei durch die |
---|
41 | t29Cache-Klasse verschiedenste Dateien überprüft. Für diese Seite sind das etwa |
---|
42 | folgende Dateien: |
---|
43 | |
---|
44 | <table class="t29-details"> |
---|
45 | <tr><th>Datei<th>Letzte Änderung |
---|
46 | <?php |
---|
47 | foreach($page_cache->test_files as $file) { |
---|
48 | print "<tr><td class='left'><tt>$file</tt><td>".(file_exists($file) ? |
---|
49 | date ("F d Y H:i:s", filemtime($file)) |
---|
50 | : "<i>does not exist</i>"); |
---|
51 | } |
---|
52 | ?> |
---|
53 | </table> |
---|
54 | |
---|
55 | <h3>Im Cache befindliche Dateien</h3> |
---|
56 | <?php |
---|
57 | $all_cache_files = getDirContents($cache_dir); |
---|
58 | ?> |
---|
59 | |
---|
60 | <p>Im <a href="/shared/cache">t29-Cache</a> auf diesem Host (<tt><?php print $host; ?></tt>) |
---|
61 | befinden sich derzeit folgende |
---|
62 | <strong><?php print count($all_cache_files); ?> Dateien und Ordner</strong>:</p> |
---|
63 | |
---|
64 | <table class="t29-details"> |
---|
65 | <tr><th>Datei<th>Letzte Änderung |
---|
66 | <?php |
---|
67 | foreach($all_cache_files as $file) { |
---|
68 | print "<tr><td class='left'><tt>$file</tt><td>".(file_exists($file) ? |
---|
69 | date ("F d Y H:i:s", filemtime($file)) |
---|
70 | : "<i>does not exist</i>"); |
---|
71 | } |
---|
72 | ?> |
---|
73 | </table> |
---|
74 | <?php> |
---|
75 | |
---|
76 | <?php |
---|
77 | // lib: |
---|
78 | |
---|
79 | // http://stackoverflow.com/questions/640931/recursively-counting-files-with-php |
---|
80 | function getFileCount($path) { |
---|
81 | $size = 0; |
---|
82 | $ignore = array('.','..','.svn'); |
---|
83 | $files = scandir($path); |
---|
84 | foreach($files as $t) { |
---|
85 | if(in_array($t, $ignore)) continue; |
---|
86 | if (is_dir(rtrim($path, '/') . '/' . $t)) { |
---|
87 | $size += getFileCount(rtrim($path, '/') . '/' . $t); |
---|
88 | } else { |
---|
89 | $size++; |
---|
90 | } |
---|
91 | } |
---|
92 | return $size; |
---|
93 | } |
---|
94 | |
---|
95 | // Delete from $path, including $path, using an recursive iterator |
---|
96 | function rrmdir($path) { |
---|
97 | if(is_file($path)) { |
---|
98 | unlink($path); |
---|
99 | return; |
---|
100 | } |
---|
101 | |
---|
102 | $i = new DirectoryIterator($path); |
---|
103 | foreach($i as $f) { |
---|
104 | if($f->isFile()) { |
---|
105 | unlink($f->getRealPath()); |
---|
106 | } else if(!$f->isDot() && $f->isDir()) { |
---|
107 | rrmdir($f->getRealPath()); |
---|
108 | } |
---|
109 | } |
---|
110 | rmdir($path); |
---|
111 | } |
---|
112 | |
---|
113 | // delete everything *below* path, but keep $path |
---|
114 | function rrmdir_sub($path) { |
---|
115 | array_map('rrmdir', glob("$path/*")); |
---|
116 | # print "Would delete:<pre> "; |
---|
117 | # var_dump(glob("$path/*")); |
---|
118 | } |
---|
119 | |
---|
120 | // get a list of all files below $dir, recursively. |
---|
121 | function getDirContents($dir, &$results = array()){ |
---|
122 | $files = scandir($dir); |
---|
123 | |
---|
124 | foreach($files as $key => $value){ |
---|
125 | $path = realpath($dir.DIRECTORY_SEPARATOR.$value); |
---|
126 | if(!is_dir($path)) { |
---|
127 | $results[] = $path; |
---|
128 | } else if($value != "." && $value != "..") { |
---|
129 | getDirContents($path, $results); |
---|
130 | $results[] = $path; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | return $results; |
---|
135 | } |
---|