Use Imagick instead of putenv() to only use 1 thread and avoid memory issues with OpenMP (#35339)

* Use Imagick to set threads instead of putenv() (#31942)

* Adapt code to the coding styles

* Changelog and PHPCS fix.

Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com>
This commit is contained in:
Niklas 2022-12-16 18:48:13 +01:00 committed by GitHub
parent d768307e69
commit 103fec668b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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.

View File

@ -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();
}