从PHP执行wkhtmltopdf失败 [英] Executing wkhtmltopdf from PHP fails
问题描述
有一些与我的主题相似的主题,但它们对我没有帮助.也许会有新的事情出现.
There have been a few topics similar to mine, but they did not help me. Maybe something new will come up.
问题:我无法执行PHP形式的wkhtmltopdf.
我的基本代码是:
exec('wkhtmltopdf http://somesite.com /home/user/file.pdf');
Problem: I can't execute wkhtmltopdf form PHP.
My basic code is:
exec('wkhtmltopdf http://somesite.com /home/user/file.pdf');
现在我已经检查了几件事:
Now a few things I already checked:
- 从控制台执行时,同一命令有效
- safe_mode已禁用-我可以在PHP中执行命令,例如
exec('ls');
正常工作 - 可以找到wkhtmltopdf的路径,并且我可以运行程序本身,例如
exec('wkhtmltopdf -V');
可以正常工作并输出版本信息 - 输出路径是可写的,具有777权限,并且
exec('wkhtmltopdf -V > /home/user/file.pdf');
可以正常工作,创建文件并将版本信息放入内部
从PHP执行 - 可以访问Internet,例如
exec('wget -O /home/user/file.pdf http://somesite.com')
可以正常工作,检索站点源并将其放入文件中 - 用passthru,shell_exec等替换exec没什么作用
- the same command works when executed from console
- safe_mode is disabled - I can execute commands in PHP, for example
exec('ls');
works fine - path to wkhtmltopdf can be found and I can run the program itself, for example
exec('wkhtmltopdf -V');
works fine and outputs versioning info - the output path is writable, it has 777 permissions and
exec('wkhtmltopdf -V > /home/user/file.pdf');
works fine, creates the file and puts versioning info inside - executing from PHP has internet access, for exemple
exec('wget -O /home/user/file.pdf http://somesite.com')
works fine, retrieves the site source and puts it into the file - replacing exec with passthru, shell_exec etc. makes no difference
结论: 我可以执行wkhtmltopdf,可以访问互联网,可以写入特定文件,但是正确的转换命令失败并返回状态1.
Concluding: I can execute wkhtmltopdf, I can access internet, I can write the specific file, but a correct conversion command fails and returns status 1.
我使用最新的Ubuntu,PHP版本是5.3.10-1ubuntu3,wkhtmltopdf版本是0.9.9. 我也在其他具有相同结果的计算机上尝试过.
I use the latest Ubuntu, PHP Version is 5.3.10-1ubuntu3, wkhtmltopdf version is 0.9.9. I tried it also on some other machine with the same retults.
任何(只是任何一个)想法将不胜感激!
Any (just ANY) ideas will be greatly appreciated!
推荐答案
在命令末尾添加2>&1
以了解确切的错误.
Add 2>&1
to the end of your command to understand the exact error.
exec('wkhtmltopdf http://somesite.com /home/user/file.pdf 2>&1');
这样,它将在Apache下运行该错误时告诉您错误.一旦知道出了什么问题,就更容易解决.在使用ImageMagick之前,我有一个类似的问题
This way it will tell you the error when running this under Apache. Once you know what's wrong, it is easier to address. I had a similar problem before with ImageMagick
这篇关于从PHP执行wkhtmltopdf失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!