Depending on configuration, Imagick processing may take time. Multiple problems exist if PHP times out before ImageMagick completed: <ol> <li>Temporary files aren't cleaned by ImageMagick garbage collection.</li> <li>No clear error is provided.</li> <li>The cause of such timeout can be hard to pinpoint.</li> </ol> This function, which is expected to be run before heavy image routines, resolves point 1 above by aligning Imagick's timeout with PHP's timeout, assuming it is set. However seems it introduces more problems than it fixes, see <a href="https://core.trac.wordpress.org/ticket/58202">https://core.trac.wordpress.org/ticket/58202</a>. Note: <ul> <li>Imagick resource exhaustion does not issue catchable exceptions (yet).See <a href="https://github.com/Imagick/imagick/issues/333">https://github.com/Imagick/imagick/issues/333</a>.</li> <li>The resource limit is not saved/restored. It applies to subsequent image operations within the time of the HTTP request.</li> </ul>
510publicstaticfunctionset_imagick_time_limit(){511_deprecated_function(__METHOD__,'6.3.0');512513if(!defined('Imagick::RESOURCETYPE_TIME')){514returnnull;515}516517// Returns PHP_FLOAT_MAX if unset.518$imagick_timeout=Imagick::getResourceLimit(Imagick::RESOURCETYPE_TIME);519520// Convert to an integer, keeping in mind that: 0 === (int) PHP_FLOAT_MAX.521$imagick_timeout=$imagick_timeout>PHP_INT_MAX?PHP_INT_MAX:(int)$imagick_timeout;522523$php_timeout=(int)ini_get('max_execution_time');524525if($php_timeout>1&&$php_timeout<$imagick_timeout){526$limit=(float)0.8*$php_timeout;527Imagick::setResourceLimit(Imagick::RESOURCETYPE_TIME,$limit);528529return$limit;530}531}
History
Introduced in 6.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.3.0
This method was deprecated.from the docblock
6.2.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-image-editor-imagick.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.