We use phpdocx to automatically generate word documents for our customers based on their reports.
The problem is embedHTML is using up a large amount of memory in php (~500mb) to generate a word document that only ends up being about 80k.
While we are able to create this word document, for anything larger we hit the server's memory limit. I was wondering if there was someway to stream the document out to a file during embedHTML or if there was some way to limit the memory usage.
Here's our code below along with memory usage dumps:
$this->endSession();//close the document div
$outputCode = '';
$outputCode .= $this->getBody();//get the html
$file = $saveInPath.$fileName;
$docx = new CreateDocx();
$docx->embedHTML($outputCode, array('parseDivsAsPs' => false, 'downloadImages' => true, 'id' => 'bodyContent'));
And here's the output:
You'll notice how the memory jumps up from 56mb to 498mb between #8 and #9.
Here's a link to the test doc file that was outputted: