0

There's around 18 000 products in a shop. When loading all in the front-end script it works. When loading them via cron(php_cli) the script times out/fails. The code:

$collection = Mage::getModel('catalog/product')->getCollection()
    ->setStoreId($storeId)
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('url_path')
    ->addAttributeToFilter('visibility', 4)
    ->addAttributeToFilter('status', 1);

I thought that it's a memory/performance issue so I added ini_set('memory_limit', '1024M'); on the top of the script and limited number of products to 20 with ->setPageSize(20)->setCurPage(1);. It still freezes when called by cron. I don't get any error report or exception.

Is it possible that 18k products are still loaded on the MySql side, despite adding page size limit, and make the server freeze?

Or does adding this limits the number of handled products to 20 on all levels of the application?

Which php/mysql settings shall I check/debug in this problem?

Sorry for a quite general question but it's difficult to choose the best approach in this situation.

4
  • I don't see any problem here. Do you know how many products are affected by the query? Have you tried putting this in a Block for example, and checked if it worked? – Julien Lachal Dec 21 '16 at 12:45
  • @JulienLachal the query works on front end(block, admin, custom controller etc.) either for 18k on 20 products. It just doesn't work via cron(php_cli) and I'm not getting any errors. – Alan Dec 21 '16 at 12:47
  • I am experiencing a similar issue. Did you find any answer to the problem? – zto zto Mar 15 '17 at 10:49
  • @ztozto Yes, I added my solution below. – Alan Mar 15 '17 at 12:49
0

The problem was caused by observer method that was called during controller_front_init_before. The method was set to redirect certain queries via 301 header to another URL. Unfortunately it fired on shell/cron call and that caused it to stop executing without any error.

In the end I used !isset($_SERVER['SHELL']) to disable redirecting on shell/cron call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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