Changing Memory Allocation In Phing

7th August 2013

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 available 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.

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

This might seem like a lot of memory to allocate to a single PHP instance, but it is sometimes needed when dealing with many thousands of steps. To view the current memory limit use the PHP function ini_get(), the following Phing commands will get the value of the memory_limit setting and print it out.

<php expression="ini_get('memory_limit');" returnproperty="limit"></php><echo>${limit}</echo>

Add new comment

The content of this field is kept private and will not be shown publicly.