Beispiel #1
0
function killOld($tab, $init, $path)
{
    $logger = " 2>&1";
    // >> logger -i 2>&1";
    $i = 0;
    while (isset($tab[$i])) {
        $commande = $path . "rc" . $init . ".d/" . $tab[$i] . " stop";
        exec($commande . $logger, $tabReturn, $verif);
        preg_match("/^[K|S][\\d]{2}(.*)\$/", $tab[$i], $nomFinal);
        logReturn($tabReturn, $nomFinal[1]);
        affichageStop($verif, $nomFinal[1]);
        $i++;
    }
}
function fetchEntitlements()
{
    $soapId = null;
    $num_updated = 0;
    logEnvironment();
    // read next_start from database, set from last call
    $start = load_next_start();
    if (empty($start)) {
        $start = timestamp(-1);
        logMsg("TEntitlement: Initializing " . dateString("next_start", $start) . "\n");
    }
    $end = timestamp();
    // now
    $page = 0;
    $pageSize = 10;
    $entitlement = new Entitlement();
    $returnCode = '200';
    do {
        logEFDS($start, $page, $pageSize, $end);
        $response = $entitlement->fetchDeltaSince($start, $page, $pageSize, $end);
        $return = $response['data']->return;
        $results = logReturn($return, "TEntitlement result:");
        $returnCode = $results['returnCode'];
        $soapId = $results['soapId'];
        // soapId of this paged call to fetchDeltaSince
        print "soapId: " . $soapId . ", page: " . $page . "\n";
        if ('200' != $returnCode) {
            logEnvironment();
            break;
        }
        $entitlements = isset($response['data']->entitlements) ? $response['data']->entitlements : array();
        // update local entitlement status:
        $num_updated += updateEntitlements($entitlements);
        $page++;
    } while (count($entitlements) > 0);
    // Update next_start to advance to the next time window
    // only if the above loop completed successfully.
    //
    // Otherwise, we want to keep it at the same value
    // so the next execution of the loop above will read
    // the same entitlements again, to get all of the data
    // hopefully with no errors the next time around.
    //
    if ('200' == $returnCode) {
        $start = $end;
        // save end as start for next time.
        $start = date('c', strtotime($end) - 60);
        // subtract 1 minute for next call to be
        // inclusive of any updates to db in last minute
        print "Total pages: " . $page . "\n\n";
        logEFDS($start, $page, $pageSize, $end);
        print "1 minute before current end: " . $start . "\n\n";
        // use next_start as the start timestamp for next call
        // save next_start to database for next call
        save_next_start($start);
    } else {
        print "Error occurred: next_start NOT updated, the same start timestamp will " . "be used for the next iteration, so all of the same data " . "will be requested again!\n\n";
    }
    $new_next_start = load_next_start();
    // check next_start new value in database
    logMsg("\nThe next execution will use startTimestamp: " . $new_next_start . "\n");
    return $num_updated;
}