简体   繁体   中英

Symfony2: KnpSnappy Bundle - Trying to access cache file as http://

I keep getting the occasional error:

Error: Failed loading page http:///home/livesmartbureau/var/cache/prod/snappy/knp_snappy58e64e79602c84.27350345.html (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1 due to network error: HostNotFoundError

It is trying to access its OWN cache file (which it wrote) as by pre-pending http://

My config.yml is as follows:

knp_snappy:
   pdf:
      enabled: true
      binary: /usr/local/bin/wkhtmltopdf
      options: []
   image:
      enabled: true
      binary: /usr/local/bin/wkhtmltopdf
      options: []
   temporary_folder: "%kernel.cache_dir%/snappy"

Controller Code:

$content = $this->render('Trace/traceHistoryDetails.html.twig',array(
    'history' => $_SESSION['trace_history'],
    'view' => 'PDF'
))->getContent();
$pdfGenerator = $this->get('knp_snappy.pdf');
$pdfGenerator->getInternalGenerator()->setTimeout(120);
return new Response($pdfGenerator->getOutputFromHtml($content), 200, array(
    'Content-Type' => 'application/pdf',
    'Content-Disposition' => 'attachment; filename="search_history.pdf"'
));

I have tried the temporary folder with quotes, and without quotes. I have tried various different temporary folders. The "snappy" folder is being created in /home/livesmartbureau/var/cache/prod.

I have looked everywhere for a resolution to this, but I am unable to find one. This issue happens OCCASIONALLY "intermittently" and not all the time and there is no pattern that I can detect of when it works and when it doesn't (content size does not seem to matter, as it sometimes happens on 1 page PDF's and other times 10 page PDF's work fine for the same twig template, just more data).

Can you try renderView instead of render ? All the documentation shows that and that's what I use:

$content = $this->renderView('Trace/traceHistoryDetails.html.twig',array(
    'history' => $_SESSION['trace_history'],
    'view' => 'PDF'
))->getContent();

I'm not sure if it will make a difference, but try it please.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM