无法让php exec工作

时间:2011-10-16 15:49:53

标签: php exec

我现在已经和它斗争了几个小时,我似乎无法解决这个问题。 尝试过exec(),shell_exec()和system()。什么都行不通。 我有这个:

exec("/usr/bin/php /var/www/vhosts/domain.com/httpdocs/shell/send.php >> /var/www/vhosts/domain.com/httpdocs/shell/paging.log &");

send.php只是:

echo 'works';

但是日志中没有任何内容。我在谷歌上搜索并阅读了一些东西,但我找不到任何帮助。

我正在运行php v.5.3.8。 安全模式已开启 我很确定这是php的路径,但无法真正找到如何找到它,所以我要继续使用phpinfo()。

EXEC( 'WHOAMI');什么也没做。是否假设在浏览器中显示?或者给你发电子邮件? 任何想法?

3 个答案:

答案 0 :(得分:1)

根据exec函数的PHP手册:

  

启用安全模式后,您只能执行安全模式   safe_mode_exec_dir之。出于实际原因,目前不允许这样做   在可执行文件的路径中包含..组件。

检查http://php.net/manual/en/ini.sect.safe-mode.php#ini.safe-mode-exec-dir

另外,请注意Web服务器用户必须具有写入日志文件的权限。

编辑:要关闭安全模式,不仅要检查 php.ini 文件,还要检查Web服务器中的虚拟主机特定配置,无论是Apache,NginX还是其他。如果您使用Plesk,请在vhosts中查找httpd.include,并确保safe_mode也设置为off。

答案 1 :(得分:1)

> The last line from the result of the command. If you need to execute 
> a command and have all the data from the command passed directly back
> without any interference, use the passthru() function. To get the output
> of the executed command, be sure to set and use the output parameter.

我不是在寻找输出,而exec()的最后两个参数是可选的。我的情况我真正需要的是能够打开桌面上的文件夹。这个确切的语法在MAMP_PRO_1.9.6中运行良好,但不再适用于MAMP_PRO_2.0.5(它已经坏了)

<?php
    exec("open /path/to/any/folder");   //  BROKEN in Mamp Pro 2.0.5
?>

答案 2 :(得分:0)

要获得输出,您需要传递第二个参数,或者您可以通过回显来获得最后一行输出。

从PHP手册:

string exec ( string $command [, array &$output [, int &$return_var ]] )

返回值:

命令结果的最后一行。如果您需要执行命令并将命令中的所有数据直接传回而没有任何干扰,请使用passthru()函数。 要获取已执行命令的输出,请务必设置并使用输出参数。