Tôi đang sử dụng phantomJS để tạo tệp PDF trong PHP qua vỏ (shell_exec
). Kịch bản hoạt động tốt trên máy chủ sản xuất, và cũng hoạt động tốt nếu tôi cắm lệnh PhantomJS trực tiếp vào thiết bị đầu cuối của tôi.Tập lệnh PhantomJS trả lại trang web trống
Nhưng nó không hoạt động khi tôi chạy tập lệnh trong môi trường dev cục bộ của mình. Tôi tự hỏi nếu có một vấn đề quyền liên quan. Tôi sẽ không bổ nhào vào chi tiết cụ thể của môi trường địa phương của tôi bây giờ kể từ khi tôi đoán đây là một vấn đề cấp cao ...
Lệnh đó là nghĩa vụ phải thực hiện thông qua 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
mã 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;
}
Bạn đã cài đặt cùng một phiên bản chưa? Vui lòng đăng ký các sự kiện 'onConsoleMessage',' onError', 'onResourceError',' onResourceTimeout' ([Ví dụ] (https://gist.github.com/artjomb/4cf43d16ce50d8674fdf)). Có thể có lỗi. –
Bạn đã thử đăng nhập giá trị của '$ output' chưa? – VolenD
@ user3584460 $ đầu ra đánh giá là sai nên đây không phải là vấn đề –