wppaste
WordPress

WP_Image_Editor_Imagick::set_imagick_time_limit(): int|null

Since
6.2.0
Source
wp-includes/class-wp-image-editor-imagick.php:513
Sets Imagick time limit.

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.

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.

Compatibility

Deprecated in WordPress 6.3.0. No longer used in core.

WordPress
since 6.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

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

Performance profile

How much work a call to WP_Image_Editor_Imagick::set_imagick_time_limit() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–33

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 36.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_action()one call below WP_Image_Editor_Imagick::set_imagick_time_limit()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Image_Editor_Imagick::set_imagick_time_limit() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!defined()9_deprecated_function(), defined()
defined() && !$php_timeout24–27_deprecated_function(), defined(), ::Imagick(), ini_get()
defined() && $php_timeout32–33_deprecated_function(), defined(), ::Imagick(), ini_get(), ::Imagick()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev369–334
8.5369–334
8.4369–334
8.3369–334
8.2369–334
8.1369–3341 fewer instruction than PHP 7.4
7.4379–334

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 3

  • _deprecated_function()Marks a function as deprecated and inform when it has been used.
  • Imagick::getResourceLimit()
  • Imagick::setResourceLimit()

Source code

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

Changelog

Introduced in 6.2.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.1.0 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.