2011-03-23 23:39:01 +01:00
|
|
|
<?php
|
|
|
|
// Full-Text RSS: Clear Cache
|
|
|
|
// Author: Keyvan Minoukadeh
|
2013-04-18 16:11:06 +02:00
|
|
|
// Copyright (c) 2012 Keyvan Minoukadeh
|
2011-03-23 23:39:01 +01:00
|
|
|
// License: AGPLv3
|
|
|
|
|
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Usage
|
|
|
|
// -----
|
|
|
|
// Set up your scheduler (e.g. cron) to request this file periodically.
|
2014-05-15 22:49:16 +02:00
|
|
|
// Note: this file must _not_ be named cleancache.php so please rename it.
|
2011-03-23 23:39:01 +01:00
|
|
|
// We ask you to do this to prevent others from initiating
|
|
|
|
// the cache cleanup process. It will not run if it's called cleancache.php.
|
|
|
|
|
|
|
|
error_reporting(E_ALL ^ E_NOTICE);
|
|
|
|
ini_set("display_errors", 1);
|
|
|
|
@set_time_limit(120);
|
|
|
|
|
|
|
|
// check file name
|
|
|
|
if (basename(__FILE__) == 'cleancache.php') die('cleancache.php must be renamed');
|
|
|
|
|
|
|
|
// set include path
|
|
|
|
set_include_path(realpath(dirname(__FILE__).'/libraries').PATH_SEPARATOR.get_include_path());
|
|
|
|
|
|
|
|
// Autoloading of classes allows us to include files only when they're
|
|
|
|
// needed. If we've got a cached copy, for example, only Zend_Cache is loaded.
|
|
|
|
function __autoload($class_name) {
|
|
|
|
static $mapping = array(
|
|
|
|
'Zend_Cache' => 'Zend/Cache.php'
|
|
|
|
);
|
|
|
|
if (isset($mapping[$class_name])) {
|
|
|
|
//echo "Loading $class_name\n<br />";
|
|
|
|
require_once $mapping[$class_name];
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-05-15 22:49:16 +02:00
|
|
|
require_once dirname(__FILE__).'/config.php';
|
2011-03-23 23:39:01 +01:00
|
|
|
if (!$options->caching) die('Caching is disabled');
|
|
|
|
|
2014-05-15 22:49:16 +02:00
|
|
|
// clean APC cache
|
|
|
|
if ($options->apc && function_exists('apc_delete')) {
|
|
|
|
$_apc_data = apc_cache_info('user');
|
|
|
|
foreach ($_apc_data['cache_list'] as $_apc_item) {
|
2014-09-15 22:24:06 +02:00
|
|
|
//var_dump($_apc_item); exit;
|
|
|
|
// APCu keys incompatible with original APC keys, apparently fixed in newer versions, but not in 4.0.4
|
|
|
|
// So let's look for those keys and fix here (ctime -> creation_time, key -> info).
|
|
|
|
if (isset($_apc_item['ctime'])) $_apc_item['creation_time'] = $_apc_item['ctime'];
|
|
|
|
if (isset($_apc_item['key'])) $_apc_item['info'] = $_apc_item['key'];
|
|
|
|
if ($_apc_item['ttl'] > 0 && ($_apc_item['ttl'] + $_apc_item['creation_time'] < time())) {
|
|
|
|
apc_delete($_apc_item['info']);
|
|
|
|
}
|
2014-05-15 22:49:16 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-23 23:39:01 +01:00
|
|
|
|
|
|
|
// clean rss (non-key) cache
|
|
|
|
$frontendOptions = array(
|
2014-09-15 22:24:06 +02:00
|
|
|
'lifetime' => $options->cache_time*60,
|
2011-03-23 23:39:01 +01:00
|
|
|
'automatic_serialization' => false,
|
|
|
|
'write_control' => false,
|
|
|
|
'automatic_cleaning_factor' => 0,
|
|
|
|
'ignore_user_abort' => false
|
|
|
|
);
|
|
|
|
$backendOptions = array(
|
|
|
|
'cache_dir' => $options->cache_dir.'/rss/',
|
|
|
|
'file_locking' => false,
|
|
|
|
'read_control' => true,
|
|
|
|
'read_control_type' => 'strlen',
|
|
|
|
'hashed_directory_level' => $options->cache_directory_level,
|
2014-05-15 22:49:16 +02:00
|
|
|
'hashed_directory_perm' => 0777,
|
|
|
|
'cache_file_perm' => 0664,
|
2011-03-23 23:39:01 +01:00
|
|
|
'file_name_prefix' => 'ff'
|
|
|
|
);
|
|
|
|
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
|
|
|
|
$cache->clean(Zend_Cache::CLEANING_MODE_OLD);
|
|
|
|
|
|
|
|
// clean rss (key) cache
|
|
|
|
$frontendOptions = array(
|
2014-09-15 22:24:06 +02:00
|
|
|
'lifetime' => $options->cache_time*60,
|
|
|
|
'automatic_serialization' => false,
|
|
|
|
'write_control' => false,
|
|
|
|
'automatic_cleaning_factor' => 0,
|
|
|
|
'ignore_user_abort' => false
|
2011-03-23 23:39:01 +01:00
|
|
|
);
|
|
|
|
$backendOptions = array(
|
|
|
|
'cache_dir' => $options->cache_dir.'/rss-with-key/',
|
|
|
|
'file_locking' => false,
|
|
|
|
'read_control' => true,
|
|
|
|
'read_control_type' => 'strlen',
|
|
|
|
'hashed_directory_level' => $options->cache_directory_level,
|
2014-05-15 22:49:16 +02:00
|
|
|
'hashed_directory_perm' => 0777,
|
|
|
|
'cache_file_perm' => 0664,
|
2011-03-23 23:39:01 +01:00
|
|
|
'file_name_prefix' => 'ff'
|
|
|
|
);
|
|
|
|
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
|
2014-09-15 22:24:06 +02:00
|
|
|
$cache->clean(Zend_Cache::CLEANING_MODE_OLD);
|