Maintenance Script

Last modified by Crucial on Mon, March 23, 2009 02:21
Source|Old Revisions  |  Back To Group

This is an old revision of the document!


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

  1. <?
  2. $db['host'] = '';                    // Database hostname
  3. $db['name'] = '';                    // Database name
  4. $db['user'] = '';                    // Database username
  5. $db['pass'] = '';                    // Database password
  6. $db['pref'] = '';                    // Database tables' prefix
  7.  
  8. if($_GET['clean'] == 'log') clean_log_tables();
  9. if($_GET['clean'] == 'var') clean_var_directory();
  10.  
  11. function clean_log_tables() {
  12.     global $db;
  13.    
  14.     $tables = array(
  15.         'log_url',
  16.         'log_url_info',
  17.         'log_visitor',
  18.         'log_visitor_info'
  19.     );
  20.    
  21.     mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
  22.     mysql_select_db($db['name']) or die(mysql_error());
  23.    
  24.     foreach($tables as $v => $k) {
  25.         mysql_query('TRUNCATE `'.$db['pref'].$k.'`') or die(mysql_error());
  26.     }
  27. }
  28.  
  29. function clean_var_directory() {
  30.     $dirs = array(
  31.         'var/cache/',
  32.         'var/log/',
  33.         'var/report/',
  34.         'var/session/',
  35.         'var/tmp/',
  36.         'downloader/pearlib/cache/*',
  37.         'downloader/pearlib/download/*'
  38.     );
  39.    
  40.     foreach($dirs as $v => $k) {
  41.         exec('rm -rf '.$k);
  42.     }
  43. }
  44. ?>

Adjust the database variables at the top accordingly.

If your tables have a prefix, don’t forget the trailing underscore!

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.

The next line of code will clear out your var directory:

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.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs