Ejemplo n.º 1
0
function PsExecute($command, $timeout = 20, $sleep = 2) {
  exec($command.'>/dev/null & echo $!',$op);
  $pid = (int)$op[0];
  $timer = 0;
  while ($timer<$timeout) {
    sleep($sleep);
    $timer += $sleep;
    if (PsEnded($pid)) return true;
  }
  PsKill($pid);
  return false;
}
Ejemplo n.º 2
0
function systemExecute($command, $timeout = 60, $sleep = 2)
{
    // Execute $command in a new process
    $pid = PsExec($command);
    if ($pid === false) {
        return 1;
    }
    $cur = 0;
    // Second, loop for $timeout seconds checking if process is running
    while ($cur < $timeout) {
        sleep($sleep);
        $cur += $sleep;
        // If process is no longer running, return true;
        if (!PsExists($pid)) {
            return 0;
        }
        // Process must have exited, success!
    }
    // If process is still running after timeout, kill the process and return false
    PsKill($pid);
    return 2;
}
Ejemplo n.º 3
0
function PsExecute($command, $timeout = 10, $sleep = 2)
{
    // First, execute the process, get the process ID
    $pid = PsExec($command);
    if ($pid === false) {
        return false;
    }
    $cur = 0;
    // Second, loop for $timeout seconds checking if process is running
    while ($cur < $timeout) {
        sleep($sleep);
        $cur += $sleep;
        // If process is no longer running, return true;
        //echo "\n ---- $cur ------ \n";
        if (!PsExists($pid)) {
            return true;
        }
        // Process must have exited, success!
    }
    // If process is still running after timeout, kill the process and return false
    PsKill($pid);
    return false;
}