PHP shell_exec()不会解析另一个目录中的php文件

时间:2019-10-26 13:16:29

标签: php shell exec shell-exec

我遇到了一个问题,已经测试了各种解决方案,但是没有一个能正常工作。 我在“ rest_of_the_address / public_html / cronjobs”文件夹中有一个名为“ kcsbtc.php”的文件,在其中我要运行一个shell_exec(),它将运行嵌套在“ rest_of_the_address / public_html / exchanges”中的另一个名为“ biki.php”的php文件如下:

try {
          $path = realpath("../exchanges/biki.php");
          echo shell_exec("php -f $path");

}
      catch (Exception $e){
          echo "There seems to be an error on $exchange";
}

它不起作用,但是如果我将biki.php移至cronjobs并使用其中一个 $ path ='biki.php'或$ path = realpath(“ biki.php”)在这两种情况下都可以正常工作,并为我提供所需的输出。 我认为这可能是与php处理程序或shell权限有关的访问其他文件夹的问题,仍然无法解决问题,有什么想法吗?

预先感谢

这是完整的代码:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL | E_STRICT);

   $path = realpath('../exchanges/Functions.php');
   include_once $path;
   $path = realpath('../exchanges/tick_updater.php');
   include_once $path;

   $servername = "localhost";
   $username = "**********";
   $password = "**********";
   $dbname = "***********";
   $table = "kcsbtcticks";

   // Create connection
   $conn = new mysqli($servername, $username, $password, $dbname);
   // Check connection
   if ($conn->connect_error) {
       die("Connection failed: " . $conn->connect_error);
   }

   $sql = "SELECT exchange, pair FROM `".$table."`";
   $result = $conn->query($sql);
   $conn->close();

   $exchanges = array();
   $pairs = array();
      if ($result->num_rows > 0) {
       // output data of each row
         while ( $row = $result->fetch_array(MYSQLI_NUM)) {
           $exchanges[] = $row[0] ;
           $pairs[] = explode("/",$row[1]);    
         }
       }
   $i = 0;

   foreach ($exchanges as $exchange){
      $base = $pairs[$i][0];
      $quote = $pairs[$i][1];
      $path = realpath("../exchanges/".$exchange.".php");
      include_once $path;
      try {
          echo $path;
          echo shell_exec("php -f $path 2>&1");

      }
      catch (Exception $e){
          echo "There seems to be an error on $exchange";
      }
      echo "<br /><br />";
      $i++;
   } 

0 个答案:

没有答案