source: t29-www/lib/wipe-cache.php @ 1391

Last change on this file since 1391 was 1189, checked in by sven, 7 years ago

Wipe-Cache: Funktioniert jetzt auch auf Windows.

File size: 3.4 KB
Line 
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
17if(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); ?>&nbsp;Dateien</b>
27gecacht.</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
39Cache-System unterstützt, sodass Seiten nur bei Änderungen gecacht werden müssen.
40Zur Verfikation, ob der Cache einer Seite invalide ist, werden dabei durch die
41t29Cache-Klasse verschiedenste Dateien überprüft. Für diese Seite sind das etwa
42folgende Dateien:
43
44<table class="t29-details">
45<tr><th>Datei<th>Letzte Änderung
46<?php
47foreach($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>)
61befinden 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
67foreach($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
80function 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
96function 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
114function 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.
121function 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}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License