Log to file output of an exec() command triggered from php

江枫思渺然 提交于 2019-12-12 01:58:53

问题


I have a php script to convert PDF files to images using imagick.

It works on my local box but in the production server it fails to execute the command but not sure about the reason because I can't see my command execution output.

No SSH access or to the admin panel.

In order to solve this I need to know how can I log to a text file the output of this command execution in the shell from my php script, so I can after the fail download it by ftp and read it.

exec('convert -density 150 -quality 100 -sharpen 0x2.0 -background white -alpha remove ' . $file->getFileInfo()->getRealPath() . ' ' . $save_to, $result, $error);

$result variable I tried to print_r($result); and it just shows me Array ().


回答1:


You can use shell_exec() which does same as exec() and will outputs for you the results to check where is the error by doing it this way.

$error = shell_exec('convert -density 150 -quality 100 -sharpen 0x2.0 -background white -alpha remove ' . $file->getFileInfo()->getRealPath() . ' ' . $save_to . ' 2>&1');

print_r($error);

exit;


来源:https://stackoverflow.com/questions/25280163/log-to-file-output-of-an-exec-command-triggered-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!