Forum


Replies: 8   Views: 3827
Replacevariablebytext very slow
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by bbreukelen  · 23-06-2016 - 08:34

I have a word template with 418 variables that I am replacing for numbers.
When calling the replaceVariableByText method it takes 3-4 seconds to complete on a single page document.
I have multiple pages to process which leads to a total processing time of 15 seconds which is too long.

I tried disabling preprocessing like this:

new CreateDocxFromTemplate($file, ['preprocessed' => true]);

This reduced the time to a few milliseconds but only a handfull of variables get replaced.
Manually calling processTemplate fixes that issue but now the same time is spent:

$docx->processTemplate(['document' => array_keys($repV)]);

So the processTemplate be it manually or automatically triggered is very slow and consumes 100% cpu while it runs.

Any ideas how to improve this?

Thanks