php shell exec hangs when using wkhtmltopdf

寵の児 提交于 2019-12-12 12:12:10

问题


I am trying to generate a PDF from HTML using PHP. I am running Mac OS X as my development environment although I would like this code to run on a production linux server.

So far I have got:

$url = escapeshellarg("http://www.google.com/");
$output = shell_exec("/usr/local/Cellar/wkhtmltopdf/0.11.0_rc1/bin/wkhtmltopdf " . $url . " /tmp/tmp_pdf.pdf 2>&1");
echo "<pre>$output</pre>";

This code does generate the PDF in the /tmp/tmp_pdf.pdf. The problem is it never does

echo "<pre>$output</pre>";

The browser just hangs saying waiting for server....

Its almost as if the shell_exec command never finishes. I notice when I run wkhtmltopdf from terminal it doesnt exit back to the command line. I get:

Loading page (1/2)
Printing pages (2/2)                                               
Done 

Then it sits there also, similar to the php script. Any ideas?


回答1:


The problem was with the version used as rexmac pointed out. Using the static binary for wkhtmltopdf fixed the issue for OP.



来源:https://stackoverflow.com/questions/11807438/php-shell-exec-hangs-when-using-wkhtmltopdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!