0

I'm trying to to enable the "Anchor" flag on a category with about 1400 products. When I click save, the page loads for a very long time (about 45 minutes) and finally gives me an internal server error 500.

I tried the same with a category with about 500 products, there it worked after about 20 minutes (still much too long but no error).

I get the following error in the php error log:

PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 33554440 bytes) in /Users/myuser/Sites/myproject/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 3551

PHP settings:

memory_limit = 1024M  # in .user.ini
max_execution_time = 18000 # in .user.ini
post_max_size = 32M
max_input_vars = 100000

MySQL Settings:

max_allowed_packet = 1024M
wait_timeout = 180

Environment:

Installation: MAMP PRO
PHP-Version: 7.0.8.

Magento Settings:

  • Version: 2.1.7
  • All indexes are set to "UPDATE BY SCHEDULE" and were run
  • Use flat category: YES (also tried with NO)
  • Use flat product: YES (also tried with NO)
  • Caches are cleared
  • Tried clearing /var/generation folder

So basically, I tried everything I could find on the internet but nothing seemed to help. Of course I can now try to set memory_limit to 2056 but then it needs like 2 hours - I don't think that's a solution.

What can I do?

0

The issue is related to the new way of URL rewrites generator in Magento2. In Magento2, URL rewrites are generated (in url_rewrite table) when user save the category. If you have a complex category structure and assign a category as child of multiple parents or using categories across different store_views , it tries to generate the URL for all combinations and hence get out of memory.

Here are some links I'd recommend you to go through so you might found a solution for your problem.

https://github.com/magento/magento2/issues/9706

https://github.com/magento/magento2/issues/10242

This is not a solution but a workaround.

I had also face the same issue with after migrating a huge Magento1 site. Here is the hack down there that is not a solution but it can confirm the issue for you. Update the following core file for instance and then try to update the category name.

M2\vendor\magento\module-catalog-url-rewrite\Observer\CategoryProcessUrlRewriteSavingObserver.php

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\CatalogUrlRewrite\Observer;

use Magento\Catalog\Model\Category;
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\Framework\Event\ObserverInterface;

class CategoryProcessUrlRewriteSavingObserver implements ObserverInterface
{
    /** @var CategoryUrlRewriteGenerator */
    protected $categoryUrlRewriteGenerator;

    /** @var UrlPersistInterface */
    protected $urlPersist;

    /** @var UrlRewriteHandler */
    protected $urlRewriteHandler;

    /**
     * @param CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator
     * @param UrlPersistInterface $urlPersist
     * @param UrlRewriteHandler $urlRewriteHandler
     */
    public function __construct(
        CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator,
        UrlPersistInterface $urlPersist,
        UrlRewriteHandler $urlRewriteHandler
    ) {
        $this->categoryUrlRewriteGenerator = $categoryUrlRewriteGenerator;
        $this->urlPersist = $urlPersist;
        $this->urlRewriteHandler = $urlPersist;
    }

    /**
     * Generate urls for UrlRewrite and save it in storage
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        /** @var Category $category */
        /* $category = $observer->getEvent()->getCategory();
        if ($category->getParentId() == Category::TREE_ROOT_ID) {
            return;
        }
        if ($category->dataHasChangedFor('url_key')
            || $category->dataHasChangedFor('is_anchor')
            || $category->getIsChangedProductList()
        ) {
            $urlRewrites = array_merge(
                $this->categoryUrlRewriteGenerator->generate($category),
                $this->urlRewriteHandler->generateProductUrlRewrites($category)
            );
            $this->urlPersist->replace($urlRewrites);
        } */
    }
}

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.