Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle time limit #333

Open
nicofff opened this issue Jul 24, 2020 · 2 comments
Open

Gracefully handle time limit #333

nicofff opened this issue Jul 24, 2020 · 2 comments

Comments

@nicofff
Copy link

nicofff commented Jul 24, 2020

Setting the time resource limit to some value, either by policy or by calling Imagick::setResourceLimit(Imagick::RESOURCETYPE_TIME,$timeout); and executing an action that exceeds that time limit causes the process to exit without returning control to the php code.

From the ImageMagick code here and here it looks like they just call _exit() when the time limit is reached. Not sure if have any control from the calling code, or if I should report this in ImageMagick as well.

Repro case (but any slow code should do):

<?php
Imagick::setResourceLimit(Imagick::RESOURCETYPE_TIME,5); 

try {
    $imagick = new Imagick("giphy.gif");
    $imagick = $imagick->coalesceImages();
    do {
        $imagick->resizeImage(10000, 10000, Imagick::FILTER_BOX, 1);
    } while ($imagick->nextImage());
    $imagick = $imagick->deconstructImages();
    $imagick->writeImages('new_10000x10000.gif', true);
} catch (\Exception $e) {
    var_dump($e);
}

I tried it both with IM6 and 7.
On IM6, o got a single

php: time limit exceeded `Operation canceled' @ fatal/cache.c/GetImagePixelCache/1700.`

before it exited

On IM7 I got a several of those, and then segfaults most of the time

@frederikbosch
Copy link

frederikbosch commented Sep 16, 2021

I do see similar messages in my error log.

php-fpm 17 [16-Sep-2021 18:40:08] WARNING: [pool www] child 6862 exited with code 1 after 8233.745596 seconds from start
php-fpm 17 php-fpm: time limit exceeded `Operation canceled' @ fatal/cache.c/GetImagePixelCache/1716.

My feeling is that this could be the result of multiple processes writing simultaneously to the pixel cache. From the comment above line 1716.

ensures that there is only a single reference to the pixel cache to be modified, updating the provided cache pointer to point to a clone of the original pixel cache if necessary.

We see this error typically with photoalbums where multiple large pictures need to be resized into thumbnails at the same time.

@drzraf
Copy link

drzraf commented Dec 24, 2021

They are 3 problems related to time limit:

  1. time limit exceeded log message does not mention ImageMagick in any way which confuse users looking for max_execution_time or similar
  2. Imagick interruption do no garbage collection (Reported an issue with WordPress https://core.trac.wordpress.org/ticket/52569 where max_execution_time stops)
  3. The time limit applies to the whole PHP script run (at least for cli) instead on single individual ImageMagick operations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants