WP_Image_Editor_Imagick::set_imagick_time_limit
Deprecated since 6.3.0. It is no longer supported and may be removed in future releases. Use
d in core instead.Sets Imagick time limit.
Depending on configuration, Imagick processing may take time.
Multiple problems exist if PHP times out before ImageMagick completed:
- Temporary files aren't cleaned by ImageMagick garbage collection.
- No clear error is provided.
- The cause of such timeout can be hard to pinpoint.
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 https://core.trac.wordpress.org/ticket/58202.
Note:
- Imagick resource exhaustion does not issue catchable exceptions (yet).
See https://github.com/Imagick/imagick/issues/333.
- The resource limit is not saved/restored. It applies to subsequent
image operations within the time of the HTTP request.
- The resource limit is not saved/restored. It applies to subsequent
Method of the class: WP_Image_Editor_Imagick{}
No Hooks.
Returns
Int|null. The new limit on success, null on failure.
Usage
$result = WP_Image_Editor_Imagick::set_imagick_time_limit();
Changelog
| Since 6.2.0 | Introduced. |
| Deprecated since 6.3.0 | No longer used in core. |
WP_Image_Editor_Imagick::set_imagick_time_limit() WP Image Editor Imagick::set imagick time limit code WP 6.9.1
public static function set_imagick_time_limit() {
_deprecated_function( __METHOD__, '6.3.0' );
if ( ! defined( 'Imagick::RESOURCETYPE_TIME' ) ) {
return null;
}
// Returns PHP_FLOAT_MAX if unset.
$imagick_timeout = Imagick::getResourceLimit( Imagick::RESOURCETYPE_TIME );
// Convert to an integer, keeping in mind that: 0 === (int) PHP_FLOAT_MAX.
$imagick_timeout = $imagick_timeout > PHP_INT_MAX ? PHP_INT_MAX : (int) $imagick_timeout;
$php_timeout = (int) ini_get( 'max_execution_time' );
if ( $php_timeout > 1 && $php_timeout < $imagick_timeout ) {
$limit = (float) 0.8 * $php_timeout;
Imagick::setResourceLimit( Imagick::RESOURCETYPE_TIME, $limit );
return $limit;
}
}