1

I have a script which imports products from XML data POSTed to it from an external source into Magento 2.1.

Everything works and imports fine, however when images are added to a product, the $product->save(); command takes around 7 seconds per image uploaded.

As a whole, it can add around 50 products without images to the system in around 4 seconds.

When images are passed in the import (hosted externally), they are downloaded locally and associated with the product before saving it.

$product->addImageToMediaGallery(
    $imageFile,
    $locations,
    false,
    false
);

I have tried using both GD and ImageMagick as the processors, but I now do not believe this to be the cause of the slowdown.

Any suggestions on where to look next to find out the source of the delay?

3
  • Have you tried timing how long it takes you to "download" the image? It's probably a good idea to have a separate script to import your images rather than having them imported in your product import. Commented Aug 23, 2016 at 15:46
  • Yes, the download happens in less than half a second... the slow down is at the point of the $product->save(); call. I wondered if it was to do with resizing the image for the various image sizes, but using ImageMagick actually increased the time by 300%!
    – chrismcb
    Commented Aug 23, 2016 at 18:34
  • Any solution for this? I have the same problem. Importing a product with an image takes 20 seconds, while without an image it takes 1 second. The images are at the root of Magento2
    – chdzma
    Commented Jun 20, 2020 at 13:14

0

Your Answer

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