Search code examples
phpimagemagickimap

Using ImageMagick and PHP IMAP together causes problems


I am developing a PHP script to replace a C# Windows service that reads client emails and converts attachments in whatever format they are in to a standard format. The IMAP piece works fine until I start converting large documents with ImageMagick, then I start getting errors in any IMAP function that attempts to execute: "Trying to get property of non-object". Also from that point, a function to save the emails to .eml files begins to save what are essentially empty files and the code to set each email to 'seen' from 'unseen' quits working.

If I skip processing of the emails with the largest attachments everything works fine.

If I run the code commenting out the ImageMagick commands it runs fine, including saving the .eml files and setting 'unseen' to 'seen', so it's something to do with ImageMagick, but I'll be damned if I can figure out what.

I've added $imagick->clear() each time an image is finished converting.

I've added this immediately after creating the $imagick object: $imagick->setResourceLimit(imagick::RESOURCETYPE_MEMORY, 256); $imagick->setResourceLimit(imagick::RESOURCETYPE_MAP, 256); $imagick->setResourceLimit(imagick::RESOURCETYPE_AREA, 1512); $imagick->setResourceLimit(imagick::RESOURCETYPE_FILE, 768); $imagick->setResourceLimit(imagick::RESOURCETYPE_DISK, -1);

Any ideas, anyone?

Thanks.


Solution

  • Your IMAP connection is likely timing out. Some servers will close the connection after very short amounts of inactivity, as low as 2 minutes for Yahoo.