Forum


Replies: 7   Views: 4246
Combining addtext and createwordmlfragment consumes huge memory resource
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 gang  · 31-10-2013 - 04:54

Hi,



I am trying to preserve line breaks taken from database content to a newly generated .docx document. Basically, I have entries in the database similar to the following:




blabalabalalalala

* bala

*bala


when the above text is put using addText($var), the line breaks seem to be removed. Hence I did the following:



$Question = array();

$QuestionArray = explode("\n",$content['Question'][$i]);

$i = 0;

foreach($QuestionArray as $QA){

    if ($i > 0){

        $Question[] = array('text'=>$QA,'lineBreak'=>true);

    } else {

        $Question[] = array('text'=>$QA);

    }

}



$temp = $Docx->addText($Question,array('rawWordML'=>true));    

$col4 = $Docx->createWordMLFragment($temp);



$Table[] = array($col4,$col5,$col6,$col7);



$TableOptions = array('size_col'=>array(400,400,400,400,400,400,400));

$TableProperties = array();

$TableProperties[0] = array('tableHeader'=>true);

$Docx->addTable($Table, $TableOptions, $TableProperties);



 



As you can see, I'd like to put the result in the table. Unfortunately, that code fragment seems to drain a huge memory resource. Any idea on how to fix this ?



 



 



 


Posted by gang  · 31-10-2013 - 05:00

For the above problem, I can see the following error message:



PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 935 bytes) in /var/www/html/3Party/docx/classes/CreateElement.inc on line 75


Posted by jorgelj  · 31-10-2013 - 09:49

Hello,



As you may check on this post:



http://www.phpdocx.com/blog-news/phpdocx-35-general-performance-benchmark



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.



Regards.


Posted by gang  · 01-11-2013 - 00:35

[quote=jorgelj]



Hello,



As you may check on this post:



http://www.phpdocx.com/blog-news/phpdocx-35-general-performance-benchmark



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.



Regards.



[/quote]



 



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%.



Regards.


Posted by jorgelj  · 01-11-2013 - 20:00

Hello,



Could you post your distribution, PHP version, and how are you running the script?



What is the size of $QuestionArray?



Regards.


Posted by gang  · 04-11-2013 - 02:57

Hi,



Thanks for your reply. Please find the following details of my system:




  • PHP: 5.5.3

  • PHPDocx: 3.3 (pro)



The array contain string value, it is a multidimensional array. I would say it is comparable to an array of size 75-100 which contain text. However, the array itself does not cause any problem when dump the content to a single variable (string) which later is used to build HTML file.



As dumping the value to HTML does not cause any problem, the temporary solution which is working for me  at the moment, is to create a .docx template and use replaceTemplateVariableByHTML.



Regards.



 


Posted by jorgelj  · 04-11-2013 - 09:22

Hello,



We'll take a look at it to solve any possible performance issue.



Regards.