不能得到php执行工作


Cant get php exec to work

我已经为此纠结了几个小时了,但我似乎无法解决。尝试了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");什么也不做。它应该在浏览器中显示吗?或者给你发邮件?什么好主意吗?

根据PHP手册exec函数:

启用安全模式时,只能执行目录中的文件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。包括,并确保safe_mode也被设置为off
> 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
?>

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

来自PHP手册:

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

返回值:

命令结果的最后一行。如果需要执行命令并让命令中的所有数据在不受任何干扰的情况下直接传回,请使用passthru()函数。要获取已执行命令的输出,请确保设置并使用output参数。