phpsymfonylibreofficesymfony-process

Libreoffice headless Process result is not returned, but waits for timeout


We are using libreoffice --headless for a while now, first via Debian and over the last months we switched to CentOS. We are using the Symfony Process command to convert a docx to pdf, the simplified command looks like:

libreoffice --headless --convert-to pdf \ 
    --outdir /home/conversionoutdir \
    /home/conversionindir/4f00ac05aee274967b.docx

The Symfony process that executes the above command is quite straight forward:

    $process = new Process($cmd);
    $process->mustRun();

Everything has been working okay, but since a couple of days the conversion isn't completed anymore and the process sits out until the 60 second timeout is reached.

Have been debugging this by doing the exact same conversion on our DEV server, where everything is just fine. Also tried to convert small and big documents, to see or the number of pages matter for reaching the timeout. Did also execute the command on the command line directly, where the conversion also is okay and finishes within a couple of seconds.

The exception is caught by our application, and is sent to the logger:

The process \"/usr/bin/libreoffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf:writer_web_pdf_Export --outdir /home/conversionoutdir /home/conversionindir/4f00ac05aee274967b.docx\" exceeded the timeout of 60 seconds.

Seems like PHP can not keep track of the process anymore. What could be going on here? Any clues on how to debug this any further?

Edit: after abstracting away the Symfony process component, setting the conversionoutdir permissions to 777 and executing the following snippet, the conversion still keeps hanging if executed from PHP:

$output = array();
exec('libreoffice --headless --convert-to pdf \ 
    --outdir /home/conversionoutdir \
    /home/conversionindir/4f00ac05aee274967b.docx', $output);
print_r($output);

Solution

  • Found the solution for this problem, somehow linux's HOME variable was changed to /root and libreoffice was not able to do the conversion to that path. Maybe this somehow changed while restarting Apache.

    Solution is to always let PHP set /tmp as the HOME variable:

    putenv('HOME=/tmp');
    

    The following posts provide more info: