因此,当我 ssh 进入我的服务器并运行以下命令时,它会按预期工作,并且脚本会正常运行(请注意,我使用的是 -f 选项):
/usr/bin/php -f /home/somefolder/test.php
Expected Output is OK: hello world
现在,当我运行不带 -f 选项的命令时,它基本上将内容显示为 html 文件(这是预期的行为):
/usr/bin/php /home/somefolder/test.php
Expected Output is OK: Content-type: text/html; charset=UTF-8
到目前为止,一切都按预期工作!
但是现在当我尝试使用 shell_exec() 从另一个 php 脚本调用这些相同的命令时,它不会执行该文件。使用 -f 选项和不使用 -f 选项都返回相同的响应。
所以使用 -f 选项:
$out = shell_exec("/usr/bin/php -f /home/somefolder/test.php");
echo $out;
Output is not ok: Content-type: text/html; charset=UTF-8
Expected Output should be: hello world
并且没有 -f 选项:
$out = shell_exec("/usr/bin/php /home/somefolder/test.php");
echo $out;
Expected Output is OK: Content-type: text/html; charset=UTF-8
因此,出于某种原因,它似乎忽略了 -f 选项。
有什么想法吗?
test.php 的内容:
<?php
echo "Hello World";
?>
慕村225694