php shell exec 在使用 wkhtmltopdf 时挂起 [英] php shell exec hangs when using wkhtmltopdf

查看:23
本文介绍了php shell exec 在使用 wkhtmltopdf 时挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 从 HTML 生成 PDF.我运行 Mac OS X 作为我的开发环境,尽管我希望此代码在生产 linux 服务器上运行.

到目前为止我有:

$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>";

此代码确实在/tmp/tmp_pdf.pdf 中生成了 PDF.问题是它从来没有

echo "

$output

";

浏览器只是挂起说等待服务器....

就好像 shell_exec 命令永远不会完成一样.我注意到当我从终端运行 wkhtmltopdf 时,它不会退出回命令行.我得到:

加载页面(1/2)打印页数 (2/2)完毕

然后它也坐在那里,类似于 php 脚本.有什么想法吗?

解决方案

问题在于用作 rexmac 的版本指出.使用 wkhtmltopdf 的静态二进制文件修复了 OP 的问题.

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?

解决方案

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

这篇关于php shell exec 在使用 wkhtmltopdf 时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆