How can the Magento caches & logs be cleared?

  • How can I go about clearing all of Magento's caches and logs by running a PHP script?

  • Create a file called cleanup.php and add the following code to it:

    switch($_GET['clean']) {
        case 'log':
        case 'var':
    function clean_log_tables() {
        $xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA);
        if(is_object($xml)) {
            $db['host'] = $xml->global->resources->default_setup->connection->host;
            $db['name'] = $xml->global->resources->default_setup->connection->dbname;
            $db['user'] = $xml->global->resources->default_setup->connection->username;
            $db['pass'] = $xml->global->resources->default_setup->connection->password;
            $db['pref'] = $xml->global->resources->db->table_prefix;
            $tables = array(
            mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
            mysql_select_db($db['name']) or die(mysql_error());
            foreach($tables as $table) {
                @mysql_query('TRUNCATE `'.$db['pref'].$table.'`');
        } else {
            exit('Unable to load local.xml file');
    function clean_var_directory() {
        $dirs = array(
        foreach($dirs as $dir) {
            exec('rm -rf '.$dir);

    Save the file to the magento root directory.

    Run the following url For Log clearing

    Run the following url for Cache clearing

    You shouldn't truncate the table `log_summary_type`

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM