Skip to content

Instantly share code, notes, and snippets.

@dev-4458
Created December 15, 2021 01:26
Show Gist options
  • Save dev-4458/10b6aa4302fb23bce1c3c4b56aa79e1f to your computer and use it in GitHub Desktop.
Save dev-4458/10b6aa4302fb23bce1c3c4b56aa79e1f to your computer and use it in GitHub Desktop.
Magento 2 : PHP Static Script for Re-Indexing
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
ini_set('display_errors', 1);
$host = $_SERVER['HTTP_HOST'];
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$indexerFactory = $objectManager->get('Magento\Indexer\Model\IndexerFactory');
$indexerCollectionFactory = $objectManager->get('Magento\Indexer\Model\Indexer\CollectionFactory');
$indexerCollection = $indexerCollectionFactory->create();
$ids = $indexerCollection->getAllIds();
foreach ($ids as $id) {
echo " create index: ".$id."<br />";
$idx = $indexerFactory->create()->load($id);
$idx->reindexAll($id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment