Title: WP_Image_Editor_Imagick::set_imagick_time_limit
Published: March 29, 2023
Last modified: May 20, 2026

---

# WP_Image_Editor_Imagick::set_imagick_time_limit(): int|null

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#wp--skip-link--target)

This method has been deprecated since 6.3.0. No longer used in core instead.

Sets Imagick time limit.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#description)󠁿

Depending on configuration, Imagick processing may take time.

Multiple problems exist if PHP times out before ImageMagick completed:

 1. Temporary files aren’t cleaned by ImageMagick garbage collection.
 2. No clear error is provided.
 3. 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](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](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.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#return)󠁿

 int|null The new limit on success, null on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#source)󠁿

    ```php
    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;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-image-editor-imagick.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-image-editor-imagick.php#L312)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-image-editor-imagick.php#L312-L333)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#related)󠁿

| Uses | Description | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_imagick_time_limit/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Deprecated. No longer used in core. | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_image_editor_imagick%2Fset_imagick_time_limit%2F)
before being able to contribute a note or feedback.