When Reindexing in Magento Fails, Use The Command Line

One of the things that you have to get used to when running Magento is dealing with the indexes that it relies on. Usually you can do this from the admin panel by going to System -> Index Management.

When indexing fails from the admin panel you get a message saying that it failed with no reason why it failed. Now in most cases you cannot ignore this. You may find that most (if not all) of your products has disappeared from the front end of the website.

While I am not entirely sure of the cause of the re-indexing failing, the one way I have discovered how to successfully re-index is to turn off your web server and run a special command line script to do your re-indexing. Not only does this almost always complete, but if it does fail it will give you an error message (I have only ever seen it give an Integrity Constraint Violation).

The command line script is located in the shell/ directory of your Magento install. The script is called indexer.php and there are a number of options you can use to do just about anything you could with the admin panel.

I would recommend playing around with on a development server so that you can become familiar with how it works so when you are ready to use it when it is crunch time.

Some Common Uses

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 <code>  - Re-indexes the <code> index
php indexer.php reindexall        - Re-indexes all the indexes

Leave a Reply

Your email address will not be published. Required fields are marked *