从php执行时,Wkhtmltopdf无法解析主机

Mis*_*iur 2 php windows wkhtmltopdf symfony

我使用wkhtmltopdf从php生成pdf,但我有一个特殊的问题.当模板不使用任何外部源时,一切都很好.但当它通过http /文件协议导入任何内容时,我得到:

The exit status code '1' says something went wrong:
stderr: ""
stdout: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[=======> ] 13%
[============================================================] 100%
Counting pages (2/6) 
[============================================================] Object 1 of 1
Resolving links (4/6) 
[============================================================] Object 1 of 1
Loading headers and footers (5/6) 
Printing pages (6/6)
[> ] Preparing
[============================================================] Page 1 of 1
Done 
Exit with code 1 due to network error: HostNotFoundError 
Run Code Online (Sandbox Code Playgroud)

例外告诉我: command: "D:\Programs\wkhtmlpdf\bin\wkhtmltopdf.exe" --lowquality "C:\Windows\TEMP\knp_snappy54d3831ed861e8.25642951.html" "C:\Windows\Temp\D60C.tmp".

在这种情况下,@import url(http://fonts.googleapis.com/css?family=Bree+Serif);它导致了这个错误,但我根本不能使用任何链接,如果我想从PHP工作.从命令行运行时,一切正常.我已经检查过php从"SYSTEM"用户执行它,所以我自己生成了一个以SYSTEM身份运行的cmd窗口,并且创建了pdf而没有任何问题.Allow_url_fopen已启用,openssl也是如此.

我正在使用KnpSnappyBundle,它使用Knp snappy库,它使用wkhtmltopdf.我已经在SO上阅读了所有与wkhtmltopdf相关的问题,但找不到答案.

PHP 5.5.5,apache 2.4.4

谢谢

更新:似乎symfony控制台组件使用proc_open做了一些魔术.

$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);

参数var_dump是

string(227) "cmd /V:ON /E:ON /C "("D:\Programs\wkhtmlpdf\bin\wkhtmltopdf.exe" --lowquality "C:\Windows\TEMP\knp_snappy54d3949bd6e035.20793656.html" "C:\Windows\Temp\2627.tmp") 1>"C:\Windows\Temp\sf_26C4.tmp" 2>"C:\Windows\Temp\sf_26C5.tmp""" 
array(3) {
    [0]=> array(2) {
        [0]=> string(4) "pipe" 
        [1]=> string(1) "r" 
    } 
    [1]=> array(3) {
        [0]=> string(4) "file" 
        [1]=> string(3) "NUL" 
        [2]=> string(1) "w" 
    } 
    [2]=> array(3) {
        [0]=> string(4) "file" 
        [1]=> string(3) "NUL" 
        [2]=> string(1) "w" 
    } 
} array(0) {

} string(24) "D:\Web\e-diagnostyka\web" array(0) {

} array(3) {
    ["suppress_errors"]=> bool(true) 
    ["binary_pipes"]=> bool(true) 
    ["bypass_shell"]=> bool(true) 
}
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到了类似的问题.它在我运行作曲家更新后开始发生.

问题出在最新版本的KnpLabs/snappy存储库中.

恢复到此存储库的早期版本(0.3.1)为我解决了问题.

有关导致问题的更改的更详细信息,请参阅:KnpLabs/snappy版本更改

希望它有所帮助.:)