Yiisoft/yii2-imagine Maximum execution time of 30 seconds exceeded

When save image and resize it on server not working

its take more than 30 seconds and throw Exception
Imagick/Image.php 292 Maximum execution time of 30 seconds exceeded

   public static function saveAndResize($image, $name, $width, $height, $small = false)
   {   $path = self::CDN_PATH . $name;

    $savePath = Yii::getAlias($path);
    if (!$image->saveAs($savePath, !$small)) {
        return false;
    }
    Image::resize($savePath, $width, $height)->save($savePath);

    if ($small) {
        $fullName = explode('/', $name);
        $path = self::CDN_PATH . $fullName[0] . "/preview/" . $fullName[1];

        self::createDirectoryIfNotExists($fullName[0] . "/preview");

        $savePath = Yii::getAlias($path);
        if (!$image->saveAs($savePath)) {
            die($savePath);
            return false;
        }
        Image::resize($savePath, 1200, 1500)->save($savePath);
    }

    return true;
}

there is no quick answer to this you have to profile your script to see exactly where the problem is I would suggest consider increasing the time to >1min and then fine tune it

1 Like