【发布时间】:2015-11-18 11:41:17
【问题描述】:
我正在使用 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;
}
【问题讨论】:
-
是否安装了相同的版本?请注册
onConsoleMessage、onError、onResourceError、onResourceTimeout活动 (Example)。可能有错误。 -
你试过记录
$output的值吗? -
@user3584460 $output 计算结果为 false,所以这不是问题
标签: php pdf-generation phantomjs