Avoid out of memory bug in php 5.2 and 5.3