How to set up log cleaning in Magento

How to set up log cleaning in Magento using Magentos Default Log Cleaning or use a custom script Parent Technology uses both for its customers.   It all depends on the customers hosting plan. In order to make sure that your Magento is not being slowed down by a huge amount of old log records, it is recommended that you set up its log cleaning function to automatically purge old logs. You can do this from the Magento admin area > System > Configuration > Advanced section > System > Log Cleaning. Once there, modify the value for Save Log, Days. The default value is 180 but we recommend changing it to 60 or even 30 days. Then set Enable Log Cleaning to Yes and click Save Config to save the changes. Note that the Log Cleaning functionality depends on the Magento cron. You need to make sure you have set up the cron in order for your log cleaning to work properly.   I also found another great script to clean Magento ----------------------------- Create a file called cleanup.php and add the following code to it: -----------------------------
  1. <?php
  2. $xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA);
  3. $db['host'] = $xml->global->resources->default_setup->connection->host;
  4. $db['name'] = $xml->global->resources->default_setup->connection->dbname;
  5. $db['user'] = $xml->global->resources->default_setup->connection->username;
  6. $db['pass'] = $xml->global->resources->default_setup->connection->password;
  7. $db['pref'] = $xml->global->resources->db->table_prefix;
  8. if($_GET['clean'] == 'log') clean_log_tables();
  9. if($_GET['clean'] == 'var') clean_var_directory();
  10. function clean_log_tables() {
  11.     global $db;
  12.     $tables = array(
  13.         'dataflow_batch_export',
  14.         'dataflow_batch_import',
  15.         'log_customer',
  16.         'log_quote',
  17.         'log_summary',
  18.         'log_summary_type',
  19.         'log_url',
  20.         'log_url_info',
  21.         'log_visitor',
  22.         'log_visitor_info',
  23.         'log_visitor_online',
  24.         'report_event'
  25.     );
  26.     mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
  27.     mysql_select_db($db['name']) or die(mysql_error());
  28.     foreach($tables as $v => $k) {
  29.         mysql_query('TRUNCATE `'.$db['pref'].$k.'`') or die(mysql_error());
  30.     }
  31. }
  32. function clean_var_directory() {
  33.     $dirs = array(
  34.         'downloader/pearlib/cache/*',
  35.         'downloader/pearlib/download/*',
  36.         'var/cache/',
  37.         'var/log/',
  38.         'var/report/',
  39.         'var/session/',
  40.         'var/tmp/'
  41.     );
  42.     foreach($dirs as $v => $k) {
  43.         exec('rm -rf '.$k);
  44.     }
  45. }
  46. ?>
Save the file to the directory where Magento resides. Next, open up cPanel and click on the Cron Jobs icon. Click on the Standard button. For the Command to run, enter the following line of code, making sure to replace the domain name with your own:
curl -s -o /dev/null http://www.domain.com/cleanup.php?clean=log
I would recommend leaving the time settings as is, so your log tables will be cleared out daily at 3 AM. Once you have this set at your preferred interval, click the Save Crontab button. If you want to have your var directory cleared out automatically, add the following line of code to a new entry:
curl -s -o /dev/null http://www.domain.com/cleanup.php?clean=var
It would be best to clean this out every 2-4 weeks, so set the Day(s) column to 14 or 30. Click the Save Crontab button once you’re done. This script may not work in all hosting environments, and I take no responsibility if you fubar your site up!

Site Search

Contact Us

 
 
 
Parent Technology Inc.
1535 Rosalind Rd Se
East Grand Rapids, MI 49506, USA
 
 

This email address is being protected from spambots. You need JavaScript enabled to view it.