Ejemplo n.º 1
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.º 2
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;
}
Ejemplo n.º 3
0
function checkFinishedTraining()
{
    global $conn;
    $log = "";
    $num_images_pending = ew_ExecuteScalar("select count(*) from training_concepts WHERE (id_training_concepts_status \t = 3)");
    echo "{$num_images_pending} training concepts processing<br>";
    if ($num_images_pending) {
        $image_to_download = EW_FLICKR_IMAGE_DOWNLOADED;
        $rs = $conn->Execute("SELECT * from training_concepts WHERE (id_training_concepts_status \t = 3 ) ");
        $rs->MoveFirst();
        while (!$rs->EOF) {
            $pid = $rs->fields('processId');
            if (PsExists($pid)) {
                echo "<br> Il concetto " . $rs->fields('name') . " con pid: {$pid} è ancora in fase di processing";
            } else {
                echo "<br> Il concetto " . $rs->fields('name') . " con pid: {$pid} ha terminato il processing";
                // die();
                $conn->Execute("UPDATE training_concepts  set id_training_concepts_status = 4,  end_processing = NOW() WHERE id = '" . $rs->fields('id') . "'");
            }
            $rs->MoveNext();
        }
    }
}