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>
512publicstaticfunctionset_imagick_time_limit(){513_deprecated_function(__METHOD__,'6.3.0');514515if(!defined('Imagick::RESOURCETYPE_TIME')){516returnnull;517}518519// Returns PHP_FLOAT_MAX if unset.520$imagick_timeout=Imagick::getResourceLimit(Imagick::RESOURCETYPE_TIME);521522// Convert to an integer, keeping in mind that: 0 === (int) PHP_FLOAT_MAX.523$imagick_timeout=$imagick_timeout>PHP_INT_MAX?PHP_INT_MAX:(int)$imagick_timeout;524525$php_timeout=(int)ini_get('max_execution_time');526527if($php_timeout>1&&$php_timeout<$imagick_timeout){528$limit=(float)0.8*$php_timeout;529Imagick::setResourceLimit(Imagick::RESOURCETYPE_TIME,$limit);530531return$limit;532}533}
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
Deprecated. No longer used in core.from the docblock
6.2.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 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.