dongzuo7166 2015-08-31 05:12
浏览 362

shell_exec()命令在本地不起作用

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;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示