KnpLabs / snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage

Home Page:https://knplabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HostNotFoundError when using symfony/process 3.1 or above

Athlon1600 opened this issue · comments

Seems to be similar to this issue: #134

but that fix did not work for me. This is my setup:

composer.json

{
  "require": {
    "symfony/process": "^2.8",
    "knplabs/knp-snappy": "^1.0"
  }
}

test.php

require("vendor/autoload.php");

use Knp\Snappy\Pdf;

$snappy = new Pdf('C:\wkhtmltox\bin\wkhtmltopdf.exe');

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="file.pdf"');

echo $snappy->getOutput('http://www.google.com');

works just fine. Now if I were to upgrade to symfony/process 3.1 or above (that's what comes with Laravel), and change nothing else, I get this:

{
  "require": {
    "symfony/process": "^3.1",
    "knplabs/knp-snappy": "^1.0"
  }
}
Fatal error:  Uncaught RuntimeException: The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
Error: Failed to load http://www.google.com/, with network status code 3 and http status code 0 - Host www.google.com not found
Error: Failed loading page http://www.google.com (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
"
stdout: ""
command: C:\wkhtmltox\bin\wkhtmltopdf.exe --lowquality "http://www.google.com" "C:\Users\Paul\AppData\Local\Temp\knp_snappy5bf09a493cb1b7.72369057.pdf". in C:\Users\Paul\Desktop\git\vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php:378
Stack trace:
#0 C:\Users\Paul\Desktop\git\vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php(177): Knp\Snappy\AbstractGenerator->checkProcessStatus(1, '', 'Loading pages (...', 'C:\\wkht in C:\Users\Paul\Desktop\git\vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php on line 378

what's the problem? I can't seem to find what has changed between symfony/process versions that broke snappy.
symfony/process@2.8...3.1

I'm using Windows by the way, and I don't know if this same problem exists on Linux platforms....

it's very interesting that it starts working if I manually add 'SystemRoot' env variable when initializing Snappy:

$env = array(
  'SystemRoot' => 'C:\\WINDOWS'
);
	  
$snappy = new Pdf('C:\wkhtmltox\bin\wkhtmltopdf.exe', array(), $env);

^ works

img

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.