本文介绍了通过浏览器执行时,PHP exec()将不执行shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定的PHP脚本,该脚本调用exec()来执行将PDF转换为JPG的命令.此命令在bash中可以正常工作.

I have a certain PHP script that calls exec() to execute a command to convert a PDF to JPG. This command works fine in bash.

要避免您最初的疑难解答猜测,请注意以下几点:

To preempt your initial troubleshooting guesses, note the following:

  • safe_mode =关闭
  • 将包含PDF和脚本的目录的权限设置为777,并且该目录也是JPG的写入位置.
  • 我传递给exec()的命令明确指向正在使用的二进制文件(例如/usr/local/bin/convert).
  • display_errors =开启
  • error_reporting = E_ALL
  • disable_functions = [空白]
  • 我正在回显exec()的输出,但不返回任何内容.默认情况下运行的命令不返回任何内容.

当我从浏览器中调用此PHP脚本时(访问 http://www.example.com/script .php ),exec()不会执行其参数.

When I call this PHP script from the browser (visiting http://www.example.com/script.php), exec() does not execute its argument.

重要:我知道我的脚本或bash命令的构造方式都没有问题,因为从bash中,我可以使用'php'执行脚本,并且脚本可以正常工作(例如'php script.php'转换文件)

IMPORTANT: I know that there are no issues with my script or the way I have constructed the bash command, because from bash, I can execute the script with 'php' and it works (e.g. 'php script.php' converts the file)

我还尝试过将exec()与system()交换出去.

I have also tried switching out exec() with system().

最后,我以前曾经遇到过这个问题,但是不记得我是如何解决的.

Last, I have had this issue once before in the past but cannot remember how I fixed it.

我知道我缺少一些东西,所以我希望其他人也能像我一样经历并记住如何解决!

I know there is something I am missing, so I hope someone else has experienced this as I have and remembers how to fix it!

在此先感谢您提供的任何帮助.

Thank you in advance for any assistance you can provide.

亚历克斯

推荐答案

在命令末尾添加2>&1以将错误从stderr重定向到stdout.这应该可以清楚地说明出了什么问题.

Add 2>&1 to the end of your command to redirect errors from stderr to stdout. This should make it clear what's going wrong.

这篇关于通过浏览器执行时,PHP exec()将不执行shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 00:51