Changing Memory Allocation In Phing

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.

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

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_get('memory_limit');" returnproperty="limit"> <echo>${limit}</echo></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.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
3 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.