Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#52569 new defect (bug)

Don't let PHP timeout in the middle of an ImageMagick operation

Reported by: drzraf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.6.1
Component: Media Keywords: has-patch
Focuses: Cc:


Depending on configuration Imagick processing may take time.

Multiple problems exist if PHP timeout before the 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 new helper is expected to be run before heavy image routines and resolves above point 1 by aligning Imagick's timeout on PHP one (assuming it's set).

Note: Imagick resource exhaustion do not catchable issue exceptions (but that would be nice to have since we would now be able to handle them).

Actual incident:

One of our declared image size was 3000px wide. But that post was given a mobile (portait-oriented image of 3000px high and only 1666px wide).

The Resizing-logic triggered WP_Image_Editor_Imagick::thumbnail_image().
But while resizeImage would take (only) ~2 seconds, unsharpMaskImage is much more expensive, especially on such big image and was taking way more time than PHP's timeout.

The thread (and the Imagemagick process) was killed, but doing so brutally, ImageMagick left a 128MB temporary-file inside /tmp every time the same HTTP request was triggered.

Said request coming from the frontend (lazy image-resizing) it quickly filled said partition until it disrupted httpd.

That's why I set this ticket's to "defect".

Change History (1)

This ticket was mentioned in PR #1019 on WordPress/wordpress-develop by drzraf.

9 months ago

  • Keywords has-patch added

Media: Don't let PHP timeout in the middle of an ImageMagick operation.

Trac ticket: https://core.trac.wordpress.org/ticket/52569

Note: See TracTickets for help on using tickets.