Sometimes it's necessary to check the indexing times in Magento, especially when it's taking a long time. The Magento indexing system is notorious for being very slow.

To check the time it takes for each index to reindex, I wrote the following little PHP script:

require_once('app/Mage.php'); //Path to Magento
ini_set('display_errors', true);
$log = '';
$indexCollection = Mage::getModel('index/process')->getCollection();
foreach ($indexCollection as $index) {
    $timeStart = microtime(true);
    $timeEnd = microtime(true);
    $timeExecution = number_format(($timeEnd - $timeStart),2);
    $code = $index->getIndexerCode();
    $log .= "Index $code took $timeExecution seconds\r\n";
$logFile = fopen('./var/log/indexing.log', 'w');
fwrite($logFile, $log);
echo nl2br($log);

Add this to a .php file in your Magento root, and open it in your browser. The script will output the execution time in your browser window, and write a log file in var/log.

When debugging indexing problems, this might come in handy for finding the issue.

Leave a Reply