Forum


Replies: 7   Views: 2710
Wordfragment in table cell significantly slows performance
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 admin  · 08-01-2018 - 15:19

Hello,

Using WordFragments is a bit slower than using plain strings, as a WordFragment is a PHP object. But it's only a bit slower, and the process should be very fast.We have run your snippet on our test servers and the output is generated in less than 0.001s.

For example, if we run the included sample Core/addTable/sample_2.php using a very old machine with PHP 5.2.11, 1GB of RAM and a single CPU, it takes:

$ time php sample_2.php

real    0m0.079s
user    0m0.064s
sys    0m0.004s

We recommend you to read the practical guides about getting the best performance when working with phpdocx:

https://www.phpdocx.com/documentation/cookbook/improve-performance-with-templates

https://www.phpdocx.com/documentation/cookbook/improve-phpdocx-performance

And test each part of your script using the PHP CLI mode or even test it using another test server. It's really difficult to guess what could be wrong; sometimes we have seen buffer limitations when working with some web servers (nginx), or issue when reading the databases or external web services or when trying to replace very long contents in very long templates (in the previous pages you can read about avoiding preprocessing a template each time a placeholder is replaced).

If you want an alternative approach, you can add plain strings placeholders instead of the WordFragments and then use the replaceVariableByWordFragment method to add the new content for each placeholder.

Regards.