Question

I have tried with below script

set_time_limit(0);
error_reporting(E_ALL | E_STRICT);
require_once 'app/Mage.php';
umask(0);
ini_set('display_errors', 1);
Mage::app('en');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$indexer="shell/indexer.php";
if(file_exists($indexer))
{

                $idxlist=array("catalog_product_attribute",
                               "catalog_product_price",
                               "catalog_product_flat",
                               "catalog_category_flat",
                               "catalog_category_product",
                               "catalog_url",
                               "catalogsearch_fulltext",
                               "cataloginventory_stock");
        //reindex using magento command line
        foreach($idxlist as $idx)
        {
            echo "reindex $idx n ";
            exec("php shell/indexer.php --reindex $idx");
        }
}

Since my store has more than 3000 products,After ran this script from root folder,it goes 504 gateway timeout error. Any possibility to print the output with out time error ?

Please advice

Was it helpful?

Solution

You're still going to incur your Apache/Nginx timeout if you're running this over HTTP.

I would personally suggest running the operation directly in command line but if that's unsuitable you could run your exec() command in the background.

 exec("php shell/indexer.php --reindex $idx > /dev/null 2>/dev/null &");

Will remove the output and run the command in another process causing your timeout to not exist. Obviously this means the script will believe it's completed straight away. This will also hide the normal and error output.

See: https://stackoverflow.com/questions/1019867/is-there-a-way-to-use-shell-exec-without-waiting-for-the-command-to-complete

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top