I'm trying to run a shell command via PHP. Interestingly, the script works fine on the production server AND it works when I plug in the command to the shell manually. But the shell_exec() command does not work in my local dev. environment on OS X - it simply returns a blank web page instead of the PDF that is supposed to be generated.
I won't dive into the specifics of my local env. for now since I'm guessing this is a high-level issue...
The command that is supposed to execute via shell_exec() looks like:
/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
The php:
public function pdfResponse($url, $script, $remote_filename)
{
$tempFile = tempnam('/tmp', 'pjs');
$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;
}
Answer:
shell_exec
is also disabled when PHP is running in safe mode
you can try with exec() command.
No comments:
Post a Comment