Php – the best way to run unoconv in php on debian server

debianopenofficePHP

I have a php script in which I need to convert doc documents to html files in order to show them in a web page.

I'm doing the conversion with the php command:

exec ( $Command, $Output, $ReturnValue ) ;

where

$Command = "/usr/bin/timeout -s 9 $TimeOut /usr/bin/unoconv -f html -o " . escapeshellarg($Dir) . " " . escapeshellarg($File) ;

Apparently everything works well, but sometimes the process doesn't end, and I remain with hundreds of soffice.bin, unoconv, oosplash processes which waste ram and definitely crash the server.

Am I missing anything?

Is there a better way to invoke unoconv?

Should I run the unoconv server as a system service?

I'm using: LibreOffice 3.5, Unoconv 0.5, apache 2.2.22-13+deb7u4

Best Answer

I recommend the following:

  • use the latest version of unoconv (at least v0.7 when it is released, or the master branch from GitHub today)

  • use the most recent stable release of LibreOffice (recent releases use less memory, are generally much faster and crash less)

  • use the native LibreOffice python binary to run unoconv, eg. /opt/libreoffice4.4/program/python /usr/bin/unoconv -f pdf file.doc

  • hardcode the python path in the unoconv script shebang, so put on the first line #!/opt/libreoffice4.4/program/python rather than #!/usr/bin/env python. (Apache/PHP usually do not set PATH, so unoconv fails)

  • ensure that the user running unoconv has write access to its HOME directory

If you do the above, everything should work out fine. If LibreOffice still crashes, you should take this up with the upstream project. Also beware that LibreOffice cannot handle more than one connection/client at the same time, so ideally your PHP script should properly lock and/or queue requests. (Look at the flock system utility for this)

If you still have any issues, please report them to: http://github.com/dagwieers/unoconv/issues