Forum


Replies: 7   Views: 2572
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 irishadar  · 08-01-2018 - 13:24

hi,

I need to chance the color of txt acoording to it's content ,

so i am using "WordFragment" :

$OwnFragment = new WordFragment($docx, 'document');
$textOwn = array();
if ($vownership === 'חסר') {
        $textOwn[]=array(
                        'text' => $vownership,
                        'color' => 'red'
                        );      
$OwnFragment->addText($textOwn);                     

and then push it into cell in table .

'OWN'=>$OwnFragment,

this small change takes over an hour to acomplish , and somtims it even fails.

is there a better way of doing what i need ?

 

best 

iris hadar

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.

Posted by irishadar  · 10-01-2018 - 07:15

Hi, thank you for your prompt response.

You absolutely write when it comes down to several items/paragraph in a page  or up to 500 rows in a table but once you go over these limits that when the performance goes down dramatically and it is not linear anymore.

Our script is very complicated, in general, it retrieves data from Oracle and places it in a table.

Sometimes the number of row goes as far as 3000.

In our specific issue we are trying to make some kind of a “switch case”  on one of the columns that  will color each status differently.

In order to dos o we are using the snippet I send earlier and push the resulting word fragment in the table array.

When we are not using the word fragment the script run within 40-50 sec , when we do use it the script runs over an hour and then it timed out.

I must emphasize that when we reduce the number of rows to 500 the script works perfectly.

 

So…my  question is can we color the column in another way? or is something wrong with our code?

Posted by admin  · 10-01-2018 - 09:01

Hello,

The dev team has tests with more than 5000 rows in a single table, a lof of them with WordFragments and the result is very fast. We recommend you to check if your server is configured correctly or it can be optimized, maybe if you are generating too many objects it's running out of memory (or using swap memory) or any other problem (buffer limits, not using an opcode...). Using Xdebug could be helpful to get the source of the problem.

Anyway, about your question: using a Premium license, DOCXCustomizer can change content styles on-the-fly, so you could generate the table using plain strings and then use DOCXCustomizer to change styles using DOCXPath queries. We recommend you to check the documentation and the included samples.

Regards.

Posted by irishadar  · 10-01-2018 - 09:06

hi,

thank you very much, we have premium so I will check what you sent me.

If it doesn't work can I use a "ticket" for support to look into it , since you have tested it and it working fine for you?

thanks again

iris hadar

Posted by admin  · 10-01-2018 - 09:17

Hello,

If you open a support ticket (https://www.phpdocx.com/support) with a script that illustrates your issue without doing external connections (such as databases or web services) the dev team will run it on the test servers to check its performance. They need to run the script changing only the path to phpdocx and to the DOCX ouput; so it should't include frameworks, CMS and other external codes.

Regards.

Posted by irishadar  · 11-01-2018 - 19:55

hi again,

I've tried all of your suggestions about performance but I can’t figure out way using “word fragments” slows the performance so much.

The Preprocessing didn’t make any change.

 I have reproduce the problem on standalone page containing  only a table with iterator.

I want to attach  both the code and the template hoping you can find what went wrong, but i cant see wher to attach files in forum.

I will open ticket as soon as can , mean time if  anybody can look into this I would be gutful.

 

In the code page the are two line representing the issue, one of them contain a simple word and the other contain  word fragment .

one  should toggle between them to see the performance changes (line 52-53).

  //'OWN'=>convert_menora_utf8('iris3'),//OwnFragment
  'OWN'=>$OwnFragment,

thanks in advanced ,

iris hadar

 

 

Posted by admin  · 12-01-2018 - 07:23

Hello,

Sorry but the forum doesn't allow to attach files. All tests done on the test servers return a good performance without issues.

Please open a support ticket with a script that illustrates your issue without doing external connections (such as databases or web services) and the dev team will run it on the test servers to check its performance. They need to run the script changing only the path to phpdocx and to the DOCX ouput; so it shouldn't include frameworks, CMS and other external codes.

We also recommend you to include in the support ticket the time taken to run the script (with and without WordFragments), so they can compare them with the test server output.

Regards.