/**
  * @static
  * @return string "windows" or "unix"
  */
 public static function getSystemEnvironment()
 {
     if (self::$systemEnvironment == null) {
         if (stripos(php_uname("s"), "windows") !== false) {
             self::$systemEnvironment = 'windows';
         } else {
             self::$systemEnvironment = 'unix';
         }
     }
     return self::$systemEnvironment;
 }
Example #2
0
 /**
  * @param $cmd
  * @param null $outputFile
  * @param null $timeout
  * @return string
  */
 public static function exec($cmd, $outputFile = null, $timeout = null)
 {
     if ($timeout && self::getTimeoutBinary()) {
         // check if --kill-after flag is supported in timeout
         if (self::$timeoutKillAfterSupport === null) {
             $out = self::exec(self::getTimeoutBinary() . " --help");
             if (strpos($out, "--kill-after")) {
                 self::$timeoutKillAfterSupport = true;
             } else {
                 self::$timeoutKillAfterSupport = false;
             }
         }
         $killAfter = "";
         if (self::$timeoutKillAfterSupport) {
             $killAfter = " -k 1m";
         }
         $cmd = self::getTimeoutBinary() . $killAfter . " " . $timeout . "s " . $cmd;
     } elseif ($timeout) {
         \Logger::warn("timeout binary not found, executing command without timeout");
     }
     if ($outputFile) {
         $cmd = $cmd . " > " . $outputFile . " 2>&1";
     } else {
         // send stderr to /dev/null otherwise this goes to the apache error log and can fill it up pretty quickly
         if (self::getSystemEnvironment() != 'windows') {
             $cmd .= " 2> /dev/null";
         }
     }
     \Logger::debug("Executing command `" . $cmd . "` on the current shell");
     $return = shell_exec($cmd);
     return $return;
 }