WP_Image_Editor_Imagick::set_imagick_time_limit(): int|null
- Since
- 6.2.0
- Source
wp-includes/class-wp-image-editor-imagick.php:513
Description
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.
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
- Scaling
- Constant
- Instructions
- 9–33
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 36.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_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.
| When | Instructions | Calls it makes |
|---|---|---|
!defined() | 9 | _deprecated_function(), defined() |
defined() && !$php_timeout | 24–27 | _deprecated_function(), defined(), ::Imagick(), ini_get() |
defined() && $php_timeout | 32–33 | _deprecated_function(), defined(), ::Imagick(), ini_get(), ::Imagick() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 36 | 9–33 | 4 | |
| 8.5 | 36 | 9–33 | 4 | |
| 8.4 | 36 | 9–33 | 4 | |
| 8.3 | 36 | 9–33 | 4 | |
| 8.2 | 36 | 9–33 | 4 | |
| 8.1 | 36 | 9–33 | 4 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 37 | 9–33 | 4 |
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.
Signature, return type and hooks compared across 5 parsed releases.
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.