Ben*_*dow 7 php pdf-generation phantomjs
我正在使用phantomJS通过shell(shell_exec)在PHP中创建PDF .该脚本在生产服务器上运行正常,如果我将PhantomJS命令直接插入终端,也可以正常工作.
但是当我在本地开发环境中运行脚本时,它不起作用.我想知道是否涉及权限问题.我现在不会深入了解当地环境的细节,因为我猜这是一个高级问题......
应该通过shell_exec()以下命令执行的命令:
/usr/local/bin/phantomjs --ignore-ssl-errors=true --debug=true ../scripts/renderTeamProfile.js https://127.0.0.1/app_dev.php/pdf/enterprise-lpc-enterprise/profile/render /private/var/tmp/pjsK2N16E.pdf
该php代码:
public function pdfResponse($url, $script, $remote_filename)
{
$tempFile = tempnam('/tmp', 'pjs');
// The extension specifies output format. Use pdf
$tempFilePdf = $tempFile . '.pdf';
rename($tempFile, $tempFilePdf);
# nginx should restrict access to the localhost URL
$urlLocal = preg_replace('/^https:..[^\/]+/', 'https://127.0.0.1', $url);
$phantomJs = $this->container->getParameter('testsite.phantomjs_cmd');
$command = $phantomJs.' --debug=true '.$script.' '.$urlLocal.' '.$tempFilePdf;
$output = shell_exec($command);
$content = file_get_contents($tempFilePdf);
$response = new Response($content, 200);
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition',
('inline; filename="' . $remote_filename . '"'));
return $response;
}
Run Code Online (Sandbox Code Playgroud)
结果发现本地安装的 phantomjs 版本与产品服务器上安装的版本不同。有趣的是,该错误发生在较新版本 (2.0.0) 与 1.9.8 中。