I have created a module inside admin, which is based on Gold rates, if admin update the gold rates for specific Carat then it will update the prices for that Carat products.

Now my problem is that, if there are less no. of products like 400, it is working fine, but when there are around 2000 products it updates the few products and then gives the 500 internal server error.

I have written the code as per the guidelines mentioned in the URL:http://www.atwix.com/magento/working-with-large-collections/

Please Please suggest, and help me.

2 Answers 2


Seems like this error might be due to keep-alive setting or also the php max execution time, check your apache/nginx error log and php error log as well. You can change the php max execution time within your observer, altough I would not recomend it, at least try it with:

ini_set('max_input_time', 3600);

Also check apache or nginx keep alive.

And if it's possible to optimize your update script try to begin with that.

  • Thanks lloiacono, ini_set didn't work for me, the only solution which worked is to optimize the update script, I am adding the solution in the answer, hope it helps to others too.
    – Ankur Jain
    Jul 30, 2015 at 11:18
  • @AnkurJain : i have also 500 server error, only i get when i export my product
    – Gem
    Jul 25, 2016 at 4:45
  • @Jeeva Rthinam: Please check the error log, and also check the memory_limit & max execution time, hope this will resolve your problem.
    – Ankur Jain
    Jul 26, 2016 at 9:31
    $write_connection = $this->_getConnection('core_write');            
                    $price_attribute_id = $this->_getAttributeId();
                    $attribute_table = $this->_getTableName('catalog_product_entity_decimal');

    $price_array = array("1002"=>12.00,"500"=>100.12); // price array corresponding to product id

$collection = Mage::getModel('product/catalog')->getCollection(); // Product collection object

// Below function is to iterate through collection faster than foreach
// passed some object like write connection, price attribute id so that we need not to create object everytime iterator will loop

                array(array($this, 'productCallback')),
                array('post' => $price_array,'write_connection'=>write_connection ,'price_attribute_id '=>$price_attribute_id ,'attribute_table'=>$attribute_table 

function productCallback($args)
$product = Mage::getModel('catalog/product');
$data = $args['post'];
$product_id = $product->getId();

$write_connection = $args['write_connection'];

$price_attribute_id = $args['price_attribute_id'];
$attribute_table = $args['attribute_table '];

                            $sql = "UPDATE " .$attribute_table . " cped
                            SET  cped.value = '".$data[$product->getId()]."'
                            WHERE  cped.attribute_id = ".$price_attribute_id."
                            AND cped.entity_id = ".$product_id;



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.