speed/timeout problem

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
musicmaster
Posts: 10
Joined: 2016-02-14T07:50:18-07:00
Authentication code: 1151

speed/timeout problem

Post by musicmaster »

I have an (webshop) application that generates a lot of formats for a lot of images.

In pseudocode it looks something like:

for hundred images
{ take the image
generate 10 formats from it (50x50, 100x100, etc)
}

This used to work ok. However, recently I increasingly get complaints about timeouts.

I am wondering whether other people have similar experiences. And does anyone have an idea what could cause this? I have been thinking about PHP 7 and antimalware software. But it could also be something else.

User avatar
fmw42
Posts: 26089
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: speed/timeout problem

Post by fmw42 »

What is your ImageMagick version and platform? What is your Imagick code for the loop?

musicmaster
Posts: 10
Joined: 2016-02-14T07:50:18-07:00
Authentication code: 1151

Re: speed/timeout problem

Post by musicmaster »

ImageMagick version 6.9.7-4 Q16 x86_64 on Linux

The first part of the code groups target formats with the same ratio together (in the test all formats had the same ratio). The second part does the actual work.

Code: Select all

 foreach($updatedformats AS $targetratio => $ratiogroup)
  { $targetratio = $targetratio/100;
    $mold = clone $src;
    if($targetratio == $sourceratio)
	{ $img = $src;
	  $newwidth = $width;
	  $newheight = $height;
	}
	else
	{ if($targetratio > $sourceratio)
	  { $newwidth = $height*$targetratio;
	    $newheight = $height;
		echo "";
		$offsetx = ($newwidth - $width)/2;
		$offsety = 0;
	  }
      else if($targetratio < $sourceratio)
	  { $newheight = $width/$targetratio;
	    $newwidth = $width;
		$offsetx = 0;
		$offsety = ($newheight - $height)/2;
	  }
	  $mold->extentImage($newwidth, $newheight, -$offsetx, -$offsety);
    }

	foreach($ratiogroup AS $format)
    { $targetname = $format[0];
      if((!isset($_POST["removexist"])) && file_exists($imgbase."-".$targetname.'.jpg')) continue;
	  $targetwidth = $format[1];
	  $targetheight = $format[2];
	  $img = clone $mold;
	  $img->setImageCompression(Imagick::COMPRESSION_JPEG);
	  $img->setInterlaceScheme(Imagick::INTERLACE_PLANE); /* alternatives: INTERLACE_NONE and INTERLACE_LINE */
	  $img->setImageCompressionQuality(97);
	  $img->stripImage();		
	  $img->resizeImage($targetwidth,$targetheight,$filter, 1);
	  if(!$img->writeImage($imgbase."-".$targetname.'.jpg'))
		  pecho("Error creating ".$imgbase."-".$targetname.'.jpg'); /* image, filename, quality */
	  $img->destroy();
	}
  }

User avatar
fmw42
Posts: 26089
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: speed/timeout problem

Post by fmw42 »

It might be an issue with PHP Imagick. Also there could be issues with a shared server environment. Has the server been upgraded for ImageMagick? I have seen issues with Linux systems doing patches rather than proper updates of ImageMagick. Version 6.9.7.4 is ancient by version, though I suspect the date of the version shows patches. Linux systems often only patch for security bugs and not for other issues. So that old a system with lots of odd patches may cause issues or there could be an issue with that version of ImageMagick, if it is that old. Has it always been this version? Do all your users use the same version of ImageMagick and Imagick?

musicmaster
Posts: 10
Joined: 2016-02-14T07:50:18-07:00
Authentication code: 1151

Re: speed/timeout problem

Post by musicmaster »

It usually depends on hosting providers. So I don't have much influence. On the tested site ImageMagick has the timestamp 20170114. Another is on a rather new server but I don't have the data for that.

What I find puzzling is that the software has been around for some time and that only recently this kind of reports are arriving.

snibgo
Posts: 12683
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: speed/timeout problem

Post by snibgo »

Servers will often have timeouts set to prevent runaway processes consuming resources. They may have become active due to increased workload.

ImageMagick has a timeout mechanism. Check your policy.xml for a name="time" entry that isn't commented out.
snibgo's IM pages: im.snibgo.com

Post Reply