PHPBB论坛手动清除缓存

时间:2014-06-11 05:59:31

标签: php caching phpbb phpbb3

我使用phpbb3论坛,并在数据库服务器上运行每日PHP脚本以更新用户的权限。

运行脚本后,我发现只有在从管理面板手动清除缓存后

我可以在论坛网站上看到这些变化。

在哪里可以找到服务器库中的清除缓存功能,以便将其添加到自动脚本中?

1 个答案:

答案 0 :(得分:2)

我不确定我从哪里取出它,但我已经使用了很长时间了。将其放在phpbb3根目录中,并将其命名为唯一的。您希望这样做,否则访问该URL的任何人都可以清除您的缓存。

如果你想把它放到你自己的脚本中,我建议你查看下面的delete_cache函数,了解它是如何完成的。

<?php
/**
*
* @package phpBB3
* @copyright (c) 2009 3Di - delete_cache.php v. 0001 - 2009-2-28
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Purges the tmp cache files based on time-frame
function delete_cache()
{
    global $phpbb_root_path;

    $phpbb_cache = ($phpbb_root_path . 'cache');

    // time in seconds the files are allowed to last into the cache dir
    $seconds_old = 1;

    // directory check-in first
    if (is_dir("$phpbb_cache")) 
    {
        $handle=opendir($phpbb_cache); 

        while (false!==($tmp_phpbb_cache_files = readdir($handle)))
        {
            // we delete everything but index.htm, .htaccess and sub-folders
            if ($tmp_phpbb_cache_files != "." && $tmp_phpbb_cache_files != ".." && $tmp_phpbb_cache_files != "index.htm" && $tmp_phpbb_cache_files != ".htaccess")
            {
                $diff = (time() - filectime("$phpbb_cache/$tmp_phpbb_cache_files"));
                if ($diff > $seconds_old)
                {
                    unlink("$phpbb_cache/$tmp_phpbb_cache_files");
                }
            } 
        }
        closedir($handle); 
    }
    // that should never happen..
    else
    {
        trigger_error('CACHE_DIR_ERROR');
    }
}

delete_cache();

?>