gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:53:03 28 4
gpt4 key购买 nike

我正在使用 wkhtmltopdf 从 php 生成 pdf,但我有一个特殊的问题。当模板不使用任何外部资源时,一切都很好。但是当它通过 http/file 协议(protocol)导入任何东西时,我得到:

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

异常告诉我: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)
}

最佳答案

我遇到了类似的问题。它在我运行 Composer 更新后开始出现。

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

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

要更详细地了解导致问题的更改,请参阅:KnpLabs/snappy version changes

希望对您有所帮助。 :)

关于php - 从 php 执行时,Wkhtmltopdf 无法解析主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28347218/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com