As you may check on this post:
PHPDocX is very fast and the peak memory use is very low. Please open your php.ini and post the value of the memory_limit option.
Thanks for your reply. In php.ini, I've setup my memory to 128M. On top of that, while debugging, I ended up putting ini_set('memory_limit',-1); but it doesn't help.
I execute 'top -M' just to see the memory consumption, and it keeps adding up. I had to stop the process when the memory consumption reach 90%.