Forum


Replies: 11   Views: 364
Transform docx to pdf using ms word with php com closes 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 admin  · 10-05-2024 - 15:28

Hello,

If you open MS Word manually and then open two or more DOCX documents, you can check in the task manager that only one PID (WINWORD.EXE name) is assigned to all documents. You can get the same information running:

tasklist /svc | findstr "WINWORD"

Please note we are not saying that PHP COM may not generate multiple PID (one for each instance), but we think doing parallel conversions in the same OS and killing WINWORD process (with taskkill) is not a proper solution because it may close more than one document at the same time. We don't see any direct option to get the PID of the program running in a PHP COM instance.
If you run:

$MSWordInstance = new COM("word.application") or PhpdocxLogger::logger('Check that PHP COM is enabled and a working copy of Word is installed.', 'fatal');
$tasklist = shell_exec('tasklist /svc /FO CSV | findstr "WINWORD"');

You can get a CSV output of the WINWORD processes, incluiding the PID. The last entry will be the last one unless another process has created another one at exactly the same moment. This information can be used to kill the related PID:

$pid_value = // get the last PID from $tasklist
shell_exec('taskkill /PID ' . $pid_value);

Of course, the best approach is knowing why that server is not working correctly and it's adding extra time when the PHP COM instance is closed. Some external setting or program or permission (we don't know) in the server may be blocking the normal PHP COM workflow. You say that one of your server doesn't have the same issue, there must be some configuration/program/setting difference between the server that is working as expected and the other server that adds the extra time to close the PHP COM instance.

Regards.