我想写一个后台任务。所以我写了一个基本脚本来查看shell_exec的工作原理脚本如下:
<?php
$op = shell_exec("php -v");
echo $op;
echo "back to the test.php";
?>
输出应该是php版本信息,但它会输出以下意外输出:
back to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.phpback to the test.php
它打印我当前页面内容59-60次,有时用content-type:text/html
我试过用另一个php文件输出是一样的
然后我尝试使用像date这样的linux命令,这是完美的 请帮我解决这个问题,我无法弄清楚出了什么问题?
我已尝试过php的绝对路径,但没有区别,也使用其他php函数,如system,exec等。
编辑注意:我已将exec函数更改为shell_exec,因为我错过了这个我在下面显示的输出来自shell_exec
更新 我没有得到问题的解决方案,但得到了问题的原因,因为服务器,脚本没有任何问题。我已写信给服务器的支持中心,但没有得到回复所以我认为这个问题已经关闭
答案 0 :(得分:0)
exec函数的语法是
string exec ( string $command [, array &$output [, int &$return_var ]] )
因此它是第二个参数$ output,它将由命令输出填充。仍然会返回数组而不是字符串版本。您需要解析该数据才能获得版本。
exec("/usr/bin/php -v", $out);
print_r($out);
另外我建议在exec函数中使用php的完整路径。
答案 1 :(得分:0)
我认为你的php.ini中禁用了exec和那些函数。您可以通过
进行检查if(function_exists('shell_exec')) {
echo "shell_exec is enabled";
} else {
echo "shell_exec is disabled";
}
打开php.ini并导航到disable_functions
部分如果在那里列出了shell_exec,请将其删除。
然后重启apache / php handler。
此外,如果启用了安全模式,则此功能将不可用。你需要禁用它。