snappy: Symfony\Component\Process\Exception\ProcessTimedOutException on PDF generation

I’m using Laravel Snappy package, and I think the problem is from Snappy itself. In my localhost (Windows 7 32bit) wkhtmltopdf 0.12.2.3 (with patched qt) everything is working fine. In the deployment machine (Windows Server 2012 R2 64bit) wkhtmltopdf 0.12.2.4 64bit, it takes about 60 seconds without any response or error… Good news I’m using Bugsnag service to track bugs and errors, and this is what I get: Symfony\Component\Process\Exception\ProcessTimedOutExceptionGET /gca/public/demandes-achat/1138/pdf The process "C:\xampp\htdocs\gca/wkhtmltopdf/bin/wkhtmltopdf.exe --lowquality "C:\Windows\TEMP\knp_snappy55a4f9ff7f5862.10272127.html" "C:\Windows\TEMP\knp_snappy55a4f9ff7fab55.21457299.pdf"" exceeded the timeout of 60 seconds. But when I tested to generate pdf from a website like google, it works fine !, with a plain html it wroks fine too. I’m getting crazy here because it’s working on my dev machine Win 7 and my computer Win 8.1 with difference wkhtmltopdf version for sure…

Btw, I’m using Bootstrap.min.css and Fontawesome.css

Please help me it’s urgent.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 33 (20 by maintainers)

Most upvoted comments

Hmm, it seems like the script is in fact hanging, since the pdf is only written after the timeout has been reached (and the script is thus terminated using a termsign 15.

The pdf looks correct though, and the exact same command runs perfectly on the CLI.

I’ve now worked around it using

use Symfony\Component\Process\Exception\ProcessTimedOutException;

$snappy->setTimeout(3);
try {
    $snappy->generate($input, $output);
} catch (ProcessTimedOutException $e) {
    // do nothing, the pdf is probably generated
}

It’s not that clean, because other reasons the process timed out aren’t handled anymore, but it works for now (if the pdf is generated in 3 seconds)

@sn0opr I have good news and bad news for you. Good news is that we are here to help Bad news is that we can not. 60 seconds is default timeout for Symfony/Process. Your error means that in 60 seconds there was no response from wkhtmltopdf. In this case the only thing is possible - networking issues. Generating pdf from local html or google website will work since it is loaded fastly. Please, check the url which you are trying to fetch. And remember that not only the html itself should be loaded in 60 seconds but all the resources which that html contains. If you just want to increase the timeout - you can set it here - https://github.com/KnpLabs/snappy/blob/3aaabad8bb36a9fbca275407874eed28f406fe24/src/Knp/Snappy/AbstractGenerator.php#L102. If you want to do that - please, consider that you use the latest snappy version. Cheers.

Again returning to this issue, I suddenly only get timeouts (existing project), but the files are generated.

Replacing the Symfony Process in the AbstractGenerator fixed it, so not sure why the Symfony Process is not responding…

protected function executeCommand($command)
    {
        exec($command, $output, $status);

        return array($status, $output, $status == 0 ? '' : $output);
    }