【发布时间】:2016-01-12 14:33:47
【问题描述】:
我正在尝试在 Symfony 中使用KnpSnappyBundle 生成 PDF,但每当我尝试运行该操作时,它都会超过 PHP 中的最长 60 秒执行时间。
下面是动作:
/**
* @Route("/download-agreement", name="download_agreement")
*/
public function downloadAgreementAction()
{
$session = new Session();
$html = $this->renderView('client-representation.html.twig', array(
'clientAgreementData' => $session->get("sessionClientAgreementData"),
"pdfStatus" => true
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="error.pdf"'
)
);
}
当我在树枝模板中对资产使用绝对 URL 时,它似乎也只超过了执行时间,例如 absolute_url(asset('css/agreement.css'))。如果我使用相对 url,那么 css 将被忽略并生成 PDF,但我当然需要样式。
有什么想法吗?
编辑:对于遇到此问题的任何人,使用绝对 url 应该在生产服务器上工作;但是,在本地主机上,您可能会遇到我遇到的问题。谢谢chalasr。
【问题讨论】:
-
听起来可能是尝试检索绝对网址时出现问题。尝试将
set_time_limit(0);作为控制器操作的第一行以消除 60 秒超时,然后查看页面是否完成,甚至尝试执行return new Response($html);以确保您仍然得到预期的结果。