Nir-Z
Nir-Z

Reputation: 869

PHPBB forums clear cache manually

I use phpbb3 forums, and run a daily php script on the db server for updating user's permissions .

After running the script I found that only after clearing the cache manually from the admin panel,

I can see the changes in the forum website.

Where can I find the clear cache function in the servers library so I can add it to the automatic script?

Upvotes: 0

Views: 3531

Answers (1)

Andy
Andy

Reputation: 50610

I'm not sure where I pulled this from, but I have been using it for a long time. Place this in your phpbb3 root directory, and name it something unique. You want to do this, otherwise anyone visiting the URL can clear your cache.

If you want to put this into your own script, I suggest looking at the delete_cache function, below for an idea of how it is done.

<?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();

?>

Upvotes: 2

Related Questions