Magento index status pending forever

MatheusJardimB picture MatheusJardimB · Dec 31, 2013 · Viewed 14.8k times · Source

I've created a Magento instance via command line and added a few products. Right after, started the re-index proccess for every indexes. The current situation is that all indexes have status pending/processing. This situation brings me a few questions:

  1. Is there any relation between this problem and the installation process? (via command line)
  2. Is it a problem? Since I didn't have noticed any side effect I'm not very concerned about it. Unless if it's spending tons of unnecessary processing.
  3. How can I fix it?

I've already executed php shell/indexer.php reindexall but nothing changed. And, if I execute php shell/indexer.php --status all indexes report as 'Pending'.

Thanks

Answer

Alan Storm picture Alan Storm · Dec 31, 2013

First: You'll want to get your terminology straight. (it can be a little confusing). A Magento index has one of three statuses.

pending
working
require_reindex

You can see the constants for these statuses here

const STATUS_RUNNING            = 'working';
const STATUS_PENDING            = 'pending';
const STATUS_REQUIRE_REINDEX    = 'require_reindex';

This can be confusing because the image Magento uses to represent these statuses use different terminology.

enter image description here

That is, when an index has a status of pending, Magento's UI represents this as Ready. When an index has a status of working, Magento's UI represents this as Processing, etc.

Further confusing things, the indexer.php command does not use this terminology -- instead it uses terms closer to the actual status

Pending
Require Reindex
Running

So, when you're saying Pending/Processing above, it's not clear what state your system is in.

Second: PHP does not have a built in queuing system — that means each index runs in an individual PHP process. This also means Magento and PHP have no (easy, reliable) way to determine if an index process is running. In order to implement the STATUS_RUNNING/Working/Running status, Magento uses lock files to keep track of an index's status. These lock files are located in

var/locks/index_process_*

When an index is "stuck" in STATUS_RUNNING/Working/Running for longer than you'd expect, it's usually because

  1. A indexer request quit half way though, and failed to clean up its log files

  2. The permissions of the files in var/locks/index_process_* are such that PHP can't write the files

Re: #2 -- If you're in the habit of using the command line indexer, you can often end up creating files that Magento, when running from the web-server/web-admin, won't be able to edit or delete. Deleting these files and then reindexing is often the best way to fix this problem.