Magento custom reindex script
Today we share with you a super-handy custom reindex script for Magento. Can be usefull if you want to reindex your store from code, for example if you have automated import or something. Place this code between <?php and ?> tags and you have your PHP reïndex script! You can change the indexes to the one you need to reindex. For example, if you don`t use flat catalog or flat category, there is no need to reïndex those.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
//Place this file in your Magento root folder, or modify the require once to match your directory. //increase execution time to 900seconds for larger stores ini_set('max_execution_time', 900); //require Magento require_once 'app/Mage.php'; $app = Mage::app('admin'); umask(0); //set error reporting error_reporting(E_ALL & ~E_NOTICE); Mage::setIsDeveloperMode(true); //array of indexes - You probably won`t use them all, modify this for your needs $indexcodes = array("cataloginventory_stock","catalogsearch_fulltext","catalog_category_flat","catalog_category_product", "catalog_product_attribute","catalog_product_attribute","catalog_product_flat","catalog_product_price", "catalog_url","groupscatalog2_category","groupscatalog2_product","tag_summary"); //reindex foreach ($indexcodes as $index) { print 'Reindex ' . $index; try { $process = Mage::getModel('index/indexer')->getProcessByCode($index); $process->reindexAll(); } catch(Exception $e) { echo 'Oops, error while reindexing index' . $index . '<br/>'; print($e->getMessage()); } } |
//Place this file in your Magento root folder, or modify the require once to match your directory. //increase execution time to 900seconds for larger stores ini_set('max_execution_time', 900); //require Magento require_once 'app/Mage.php'; $app = Mage::app('admin'); umask(0); //set error reporting error_reporting(E_ALL & ~E_NOTICE); Mage::setIsDeveloperMode(true); //array of indexes - You probably won`t use them all, modify this for your needs $indexcodes = array("cataloginventory_stock","catalogsearch_fulltext","catalog_category_flat","catalog_category_product", "catalog_product_attribute","catalog_product_attribute","catalog_product_flat","catalog_product_price", "catalog_url","groupscatalog2_category","groupscatalog2_product","tag_summary"); //reindex foreach ($indexcodes as $index) { print 'Reindex ' . $index; try { $process = Mage::getModel('index/indexer')->getProcessByCode($index); $process->reindexAll(); } catch(Exception $e) { echo 'Oops, error while reindexing index' . $index . '<br/>'; print($e->getMessage()); } }
Very usefull and working for me on Magento 1.7. Thanks!!
Not working for me..
Hi, where did you place the file? And did you add tags to surround the file?
I did place it in my root installation folder and I have added the <?php tags. I get an error something like 'headers already sent by blabla…'
Look for extra whitespaces or linebreaks before and after your PHP close and opening tags and remove those. Let me know if it helped
AWESOME 🙂 It is working now!! Thanks, so silly that I did not know this.
Thanks!!