ProtocolUnknownError when executing wkhtmltopdf from PHP with header and footer?

I have a strange problem with wkhtmltopdf executed from PHP. My PHP code looks like this:

  exec('wkhtmltopdf --header-html "" 
     --footer_html ""
     /tmp/pdf.html /tmp/pdf.pdf');

When I execute the same command from shell, it works perfectly. However, when I try to run it from PHP like mentioned above, the script runs until it time outs resulting in empty PDF file.

As I searched web, I tried to run it with > /tmp/error_log.txt 1>&2 parameter and I found out when executed from PHP it returns error:

Exit with code 1 due to network error: ProtocolUnknownError

More interestingly, when I delete --footer-html and --header-html it works fine executed from PHP. But obviously the resulting PDF is missing header and footer.

Header and footer HTML doesn’t have any external resource references. And I don’t think it is network / DNS problem because from commandline from the same server it works fine.

I would be very glad for any hints and tips, because this is driving me crazy. Thanks in advance.

Source: shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.