Magento – Clean log tables using Cron job

First you need to create php file called clean_log.php and paste the following code:

<?
$xml = simplexml_load_file('app/etc/local.xml');
 
$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['name'] = $xml->global->resources->default_setup->connection->dbname; 
 
global $db;
$tables = array(
        'dataflow_batch_export',
        'dataflow_batch_import',
        'log_customer',
        'log_quote',
        'log_summary',
        'log_summary_type',
        'log_url',
        'log_url_info',
        'log_visitor',
        'log_visitor_info',
        'log_visitor_online',
        'report_event'
);
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());
     mysql_query('ALTER TABLE `'.$db['pref'].$k.'` AUTO_INCREMENT=1') or die(mysql_error());
}
echo 'Cleared all log tables';

Put clean_log.php file on your magento root directory

Second, create a new cron job

0 0 * * * php /home/youraccount/public_html/clean_log.php

(Run this script once a day at 0h00)

Facebook comments:

Security Code:

line
Powered by Brother Bui