Forum


Replies: 6   Views: 3929
Phpdocx consuming cpu when replacing template
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  · 13-05-2016 - 06:16

Hello,

The first tip to improve the performance is to disable the autorepair option.
This is the signature of the constructor of CreateDocxFromTemplate.inc:
 
    /**
     * Construct
     * @param string $docxTemplatePath path to the template we wish to use
     * @param array $options
     * The available keys and values are:
     *  'preprocessed' (boolean) if true the variables will not be 'repaired'. Default value is false
     * @access public
     */
    public function __construct($docxTemplatePath, $options = array())
    {

 

By default phpdocx repairs the placeholders (sometimes Word breaks the XML content adding nonneeded tags in the strings), so to get the best performance you need to disable it:
 
$docx = new CreateDocxFromTemplate('template.docx', array('preprocessed' => true));

The second tip is to split the DOCX in two or more documents. Instead of working with a single document, please separate it, for example in two or three DOCX, and in your code replace the document placeholders and then use the MultiMerge class to merge them.

We also advise you to check PHP config (APC is highly recommended) and the server specs.

Regards.