Monday, 14 November 2011

Magento Indexing through command line - ssh

It is normal that Magento indexing takes long time or issue with browser memory limit or connection time-out. So you can try the command line alternative through the SSH connection of the website.

Way 1:

Go to yoursite/public_html/

Then

$ cd shell

php indexer.php                   - Displays help information on how to use the script
php indexer.php --status          - Shows the status of all the indexes
php indexer.php info              - Shows the "codes" for the individual indexes
php indexer.php --reindex   - Re-indexes the index
php indexer.php reindexall        - Re-indexes all the indexes



This also output the valuable error if indexing fails with any reason.

Way 2.

Create a file named "indexing.php" with following code.

// Code ends

ini_set("display_errors","On");
set_time_limit(0);
ini_set('memory_limit','1024M');
require_once './app/Mage.php';

umask( 0 );
Mage :: app( "default" );

if(defined('STDIN') )
{
echo("Running from CLI \n");
$processNo=isset($argv[1])?$argv[1] : 1;
}
else
{
echo("Running through Browser
");
$processNo=(isset($_GET['process']))? $_GET['process'] : 1 ;
}

echo "\n
Started Indexing At:  " . date("d/m/y h:i:s");
$process = Mage::getModel('index/process')->load($processNo);
$process->reindexAll();
echo "\n
Indexing Completes At: ".date("d/m/y h:i:s");
// Code ends

Now you can run this file through browser with url below:

www.yoursite.com/indexing.php?process=1

or

run it through ssh (RECOMMENDED)

php indexing.php 1

//assume that your working directing is public_html where magento resides.

// List of Process No.

1    Product Attributes       Index product attributes for layered navigation building
2    Product Prices           Index product prices
3    Catalog URL Rewrites     Index product and categories URL rewrites
4    Product Flat Data        Reorganize EAV product structure to flat structure
5    Category Flat Data       Reorganize EAV category structure to flat structure
6    Category Products        Indexed category/products association
7    Catalog Search Index    Rebuild Catalog product fulltext
8    Stock Status             Index Product Stock Status
9    Tag Aggregation Data     Rebuild Tag aggregation data

9 comments :

  1. Super-Duper site! I am loving it!! Will come back again. I am bookmarking your feeds also

    ReplyDelete
  2. awesome blog! i liked your way of description.http://www.papajogosmario.com

    ReplyDelete
  3. I simply desired to thank you very much again. I'm not certain the things I would have undertaken in the absence of the recommendations documented by you regarding such a question. This was a real frightening issue in my position, nevertheless understanding a expert manner you dealt with the issue made me to cry with happiness. I'm grateful for the guidance and trust you really know what a great job you happen to be getting into educating the rest through the use of your webpage. I know that you haven't got to know any of us.

    ReplyDelete
  4. good post. thank for sharing.http://www.porcelanatoportinari.com

    ReplyDelete
  5. Hello. Thanks, it's very useful and important information. We have an article on the similar topic posted here http://www.atwix.com/magento/process-magento-indexes-from-command-line/ you're welcome to check it out and leave your feedback.

    ReplyDelete
  6. We have just released a little patch that optimizes time processing when "Catalog Url Rewrites" is launched.

    For example:

    With 9500 references (SKU), shared (or not) between 900 categories / Sub-categories and with CMS pages, the number of generated URLs in the «Core_URL_Rewrite» table is about 80 000.

    The re-index (launched manually or by CRON) lasts about 3h30.

    After installing this patch, the re-index duration is about 1 minute!

    Full article & Benchmark available @
    http://www.dnd.fr/2012/09/magento-patch-how-to-optimize-re-index-processing-time-for-url-rewrite/

    ReplyDelete
  7. You have brought up a very superb points , thanks for the post.

    ReplyDelete
  8. Great Read! I am impressed on how you make your article easy to understand. I'll come back for more :D

    Japs Buidon is a Social Media Specialist and belongs to a team of Magento Developer in Florida. He loves hiking as well as electronics.

    ReplyDelete