【问题标题】:PHP file not gettinig executed as expectedPHP文件未按预期执行
【发布时间】:2018-10-23 13:27:02
【问题描述】:

我创建了一个php文件,如下所示。

    <?php
    $ar = 4600;
    $az = "redshift -O ".$ar;
    echo "Command executed: ";
    echo $az;
    system($az,$status); // It is not working on browser but working on terminal.
    system("ls",$asd); // It is working on both browser and terminal.
    if($status == NULL) {
        echo "<h3>Operation not successful</h3>";
    }
    else 
        echo "<h3>Temperature Succesfully set to ".$ar."</h3>";
    ?>

问题是这样的
当我使用命令在终端上运行此文件时

php file.php

“ls”命令正在执行,“redshift -O 4600”也正在执行。
但是当我使用 url 在浏览器上执行这个文件时。

127.0.0.1/file.php

只有“ls”命令被执行。 'redshift -O 4600' 没有被执行。有什么方法可以让我执行这样的程序。 我也尝试过其他功能,如 exec 等。

【问题讨论】:

  • redshift 的完整路径?权限问题?
  • 我将路径更改为 /usr/bin/redshift 但仍然没有执行
  • 从终端运行脚本的用户和运行apache的用户一样吗?
  • @xatzistnr 可能是正确的。 var_dump($status) 的输出是什么,它应该包含一个返回代码来说明问题?
  • var_dump($status) 的输出是 (int)1。

标签: php apache web-services server


【解决方案1】:

当您在 /var/www/html 位置设置服务器时,它将无法工作,公众使用该位置通过 localhost 访问您的计算机。而且由于在 localhost 中没有 redshift 之类的东西,所以它不会运行任何东西,并且操作将被执行,您将看不到任何后遗症。因此,要在 localhost 上运行系统命令,您必须在 /var/www/html 以外的任何文件夹上运行服务器。因此,要在任何其他位置运行服务器,只需转到该位置并运行 php -S localhost:8080.

【讨论】:

  • 是的,非常感谢。那么这是否意味着我可以运行多个服务器实例。因为,现在我可以从两个位置执行 php 脚本 s
  • 是的,你可以@GauravKandoria
猜你喜欢
  • 1970-01-01
  • 2015-01-27
  • 1970-01-01
  • 2013-08-20
  • 2017-12-15
  • 2011-02-25
  • 2012-11-23
  • 2014-10-20
  • 2015-09-17
相关资源
最近更新 更多