Changing Memory Allocation In Phing

7th August 2013 - 2 minutes read time

Running complex tasks in Phing can mean running out of memory, especially when altering or changing lots of files. I was recently working on a image sorting Phing project that sorted images based on EXIF information. The many thousands of files involved, along with the custom target used to extract the EXIF data caused the default avai

<php expression="ini_set('memory_limit', '1G');"></php>

lable memory to run out quite quickly.

There is no direct way to alter the PHP memory limit setting through Phing, but it can easily be altered using a Phing php task. This evaluates the PHP function ini_set() and set the memory_limit value. The following Phing task sets this limit to be 1G, or 1 gigabyte.