Saturday, February 4, 2012
Clean up cache and log for magento
Create cleanup.php file in document root folder then put these code to it, edit database variables, save and run cleanup.php?clean=log or cleanup.php?clean=var
<?
$db['host'] = ''; // Database hostname
$db['name'] = ''; // Database name
$db['user'] = ''; // Database username
$db['pass'] = ''; // Database password
$db['pref'] = ''; // Database tables' prefix
if($_GET['clean'] == 'log') clean_log_tables();
if($_GET['clean'] == 'var') clean_var_directory();
function clean_log_tables() {
global $db;
$tables = array(
'log_url',
'log_url_info',
'log_visitor',
'log_visitor_info'
);
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());
foreach($tables as $v => $k) {
mysql_query('TRUNCATE `'.$db['pref'].$k.'`') or die(mysql_error());
}
}
function clean_var_directory() {
$dirs = array(
'var/cache/',
'var/log/',
'var/report/',
'var/session/',
'var/tmp/',
'downloader/pearlib/cache/*',
'downloader/pearlib/download/*'
);
foreach($dirs as $v => $k) {
exec('rm -rf '.$k);
}
}
?>
Reference: http://www.magentocommerce.com/boards/viewthread/36148/#t117754
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment