Friday, August 16, 2013

Script to refresh Cache and Index in Magento

Let's place a file in the Magento root called "maintanance.php"
$path = '/your/magento/root');
echo("Refresh the Cache \n");
$return = shell_exec("php shell/refreshCache.php");
echo $return."\n";
echo 'Refreshing Cache';
#php shell/refreshCache.php
echo("Reindexing...this could take a while  \n");
$return = shell_exec("php shell/indexer.php --reindexall");
echo $return."\n";
#php shell/indexer.php --reindexall
Create in shell folder refreshCache.php
$magePath = 'app/Mage.php';
require_once($magePath);


try {
 $allTypes = Mage::app()->useCache();
 foreach($allTypes as $type => $blah) {
  Mage::app()->getCacheInstance()->cleanType($type);
 }
} catch (Exception $e) {
 // do something
 error_log($e->getMessage());
 Mage::log($e->getMessage());
}

No comments:

Post a Comment