Code sample # 1

$customer_obj = Mage::getModel('customer/customer');
$customer_data = $customer_obj->load(customer_id);

Code sample # 2

$customer_obj = Mage::getModel('customer/customer');

The loop count will be something around 1800-2000 every day.It is one time cron job every day

I am assuming it in this way, in sample # 1 $customer_data will have the entire customer details in memory and from there on wards it will fetch it from memory.but in sample # 2 it always hit db with every load call

Can someone please enlighten me?

2 Answers 2


For your question:

code sample 1 is better, because it only does the load once for each customer. code sample 2 does multiple loads per customer.

But as Patrick Steenks mentions, it is even much better to use a customer collection to do this, because then you only have ONE query for ALL customers :)

  • Thanks for that. But my customer base is almost 160,000. is it good to load that much of data in order to get the detail of <2000 customers?
    – zamil
    Jul 5, 2014 at 12:10
  • @zamil You can Filter the collection to the IDs you want by using ->addAttributeToFilter('entity_id', array('in' => array(1,2,3,4))) this Would get customers with IDs 1, 2, 3 and 4
    – mpaepper
    Jul 5, 2014 at 18:02
  • Or you can filter with specific conditions. Do a google search on which attribute you want to filter and you will get enough results. Jul 6, 2014 at 7:27

I think it is better to use the collection method of magento, and then only load the attributes you need:

$collection = Mage::getModel("customer/customer")->getCollection()->addAttributeToSelect('firstname','email');

Then loop with a foreach through this collection.


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.