简体   繁体   English

通过Symphony Process Component使用unoconv将文档转换为pdf

[英]Convert documents into pdf using unoconv through Symphony Process Component

I'm trying to convert word documents into PDF using unoconv in PHP. 我正在尝试使用PHP中的unoconv将Word文档转换为PDF。 When I run the following command in CLI it works properly without any error: 当我在CLI中运行以下命令时,它可以正常工作而不会出现任何错误:

export HOME=/tmp/converts && unoconv -f pdf -o ~/da063764384fb612971bfc92c52c40fc.pdf ~/da063764384fb612971bfc92c52c40fc.docx

But the problem is when I try to run it in PHP as follow: 但是问题是当我尝试按以下方式在PHP中运行它时:

$env  = ['PATH' => '/sbin:/bin:/usr/sbin:/usr/bin'];
$bash = "export HOME=${tmpDir} && /usr/bin/unoconv -f pdf -o ~/${fileName}.pdf $srcFile";$process = new Process($bash);
$process->setTimeout(120);
$process->run(null, $env);

$output = "\nOutput: " . $process->getOutput();
$error  = "\nError: " . $process->getErrorOutput();

This results: 结果:

Output:
Error: unoconv: RuntimeException during import phase: Office probably died. Binary URP bridge disposed during call

Any one has any idea how can I fix the issue!? 任何人都知道如何解决该问题!?

unoconv spawns a child libreOffice process, and then connects to that process via port 2002. strangely the port never changes. unoconv生成一个子libreOffice进程,然后通过端口2002连接到该进程。奇怪的是,该端口从未更改。 unoconv cannot therefore run in parallel, if you have one instance running all the others fail. 因此,如果您有一个实例运行所有其他实例,则unoconv无法并行运行。 That was the thing happened on my server. 那就是我服务器上发生的事情。

I ran bellow command on CLI to find all libreOffice processes: 我在CLI上运行bellow命令以查找所有libreOffice进程:

ps aux | grep libre

Then killed those process by running: 然后通过运行杀死这些进程:

ps aux | grep -i libre | awk {'print $2'} | xargs kill -9

Generally speaking, using another tool(s) which supports multi treading is a better solution for such cases. 一般而言,对于此类情况,使用支持多踩踏的其他工具是更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM