root/dev/cron/cron_clearup.php @ 449

Revision 449, 1.5 KB (checked in by kovell, 11 years ago)

Page cache uses subdirectories to split cache files. clearup cron script has longer expiry times on page and query cache. fetch and import cron scripts have commented code removed.

Line 
1<?php
2
3$KB_HOME = preg_replace('/[\/\\\\]cron$/', '', getcwd());
4chdir($KB_HOME);
5
6require_once('kbconfig.php');
7require_once('common/includes/globals.php');
8require_once('common/includes/class.config.php');
9require_once('common/includes/db.php');
10
11remove_old(7 * 24, config::get('cache_dir').'/');
12remove_old(7 * 24, config::get('cache_dir').'/'.KB_SITE.'/', true);
13remove_old(1 * 24, "cache/templates_c/");
14remove_old(7 * 24, "cache/mails/");
15remove_old(30 * 24, "cache/", true);
16
17//! Remove old files from the given directory.
18
19/*! \param $hours The oldest a file can be before being removed.
20 *  \param $dir The directory to remove files from.
21 *  \param $recurse Whether to clear subdirectories.
22 */
23function remove_old($hours, $dir, $recurse = false)
24{
25        $seconds = $hours*60*60;
26
27        $files = scandir($dir);
28
29//      echo $dir."<br>".$hours." hours<br>\n";
30        foreach ($files as $num => $fname)
31        {
32                if (file_exists("{$dir}{$fname}") && !is_dir("{$dir}{$fname}") && substr($fname,0,1) != "." && ((time() - filemtime("{$dir}{$fname}")) > $seconds))
33                {
34                        $mod_time = filemtime("{$dir}{$fname}");
35                        if (unlink("{$dir}{$fname}"))
36                        {
37                                $del = $del + 1;
38//                              echo "Deleted: {$del} - {$fname} --- ".(round((time()-$mod_time)/3600))." hours old<br>\n";
39                        }
40                }
41                // Clear subdirectories if $recurse is true.
42                if ($recurse && file_exists("{$dir}{$fname}") && is_dir("{$dir}{$fname}")
43                         && substr($fname,0,1) != "." && $fname != "..")
44                {
45                        remove_old($hours, $dir.$fname."/");
46                }
47        }
48}
Note: See TracBrowser for help on using the browser.