diff --git a/plugins/woocommerce/changelog/pr-35339 b/plugins/woocommerce/changelog/pr-35339 new file mode 100644 index 00000000000..d35dcd7f381 --- /dev/null +++ b/plugins/woocommerce/changelog/pr-35339 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Use Imagick functions to set parallel thread count instead of direct putenv call as suggested in https://core.trac.wordpress.org/ticket/36534#comment:129. diff --git a/plugins/woocommerce/includes/class-wc-regenerate-images-request.php b/plugins/woocommerce/includes/class-wc-regenerate-images-request.php index 047a9e2f2a4..340c743dae8 100644 --- a/plugins/woocommerce/includes/class-wc-regenerate-images-request.php +++ b/plugins/woocommerce/includes/class-wc-regenerate-images-request.php @@ -33,8 +33,14 @@ class WC_Regenerate_Images_Request extends WC_Background_Process { $this->prefix = 'wp_' . get_current_blog_id(); $this->action = 'wc_regenerate_images'; - // This is needed to prevent timeouts due to threading. See https://core.trac.wordpress.org/ticket/36534. - @putenv( 'MAGICK_THREAD_LIMIT=1' ); // @codingStandardsIgnoreLine. + // Limit Imagick to only use 1 thread to avoid memory issues with OpenMP. + if ( extension_loaded( 'imagick' ) && method_exists( Imagick::class, 'setResourceLimit' ) ) { + if ( defined( 'Imagick::RESOURCETYPE_THREAD' ) ) { + Imagick::setResourceLimit( Imagick::RESOURCETYPE_THREAD, 1 ); + } else { + Imagick::setResourceLimit( 6, 1 ); + } + } parent::__construct(); }