PHP 文件未按预期执行

标签 php apache web-services server

我创建了一个 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 等。

最佳答案

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

关于PHP 文件未按预期执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50320944/

相关文章:

php - 使用 Axios 获取并保存 Excel 文件

php - 为什么 Apache 不能同时处理多个请求?

php - Ubuntu 14.04 上 Laravel 5.1 的本地主机错误

c# - 如何向 Silverlight 客户端公开 .Net 2.0 Web 服务?

php - Symfony2 : how to check if an action is secured?

php - MySql 多表还是一张大表?

PHP 因 mySQL 错误而停止,但 INSERT 已记录到数据库中

php - 这个php代码有什么问题?

wcf - 具有Powershell的WCF消息级别用户凭据

ios - 尝试调用 Web 服务方法时从 NSURLResponse 返回的错误数据