1

I need to set magento all cache and magento reindex automatically, how can i done by using cron.

2

for reindexing you can use below cron

0 0 * * * php -f /path_to_your_magento/shell/indexer.php reindex

for caching you can add below cron

0 0 * * * rm -rf /path_to_your_magento/var/cache/*
  • what is : rm & -f ? – Gem May 10 '17 at 6:14
1

Magento has a class that specifically handles command line scripts. The Magento bootstrap can be handled via the Shell Abstract script inside of your shell/ folder.

<?php

include_once 'abstract.php';

class JohnG_Shell_Cron extends Mage_Shell_Abstract {

    public function run() {
        $this->_clearindex();
        $this->_clearCache();
    }

    protected function _clearindex() {
        for ($i = 1; $i <= 9; $i++) {
            $process = Mage::getModel('index/process')->load($i);
            $process->reindexAll();
            }
    }

    protected function _clearCache() {
        $allTypes = Mage::app()->useCache();
            foreach($allTypes as $type => $cache) {
                   Mage::app()->getCacheInstance()->cleanType($type);
            }
    }
}

Now setup your cron like this:

0 0-23/2 * * * php -f /path/to/your/magento/shell/johngscript.php

  • which location i paste this code – user51361 Mar 4 '17 at 6:20
  • Inside shell folder, this script work with magento 1x,if this help please upvote answer – Kishan Sanghani Mar 4 '17 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy