Esempio n. 1
0
 $domXmlFile->Load(get_ini('UPLOAD_FOLDER') . 'queue/' . $jobName);
 if ($domXmlFile->schemaValidate('plugins/core/xsd/core.xsd')) {
     if ($procM->getId($jobName) == 0) {
         $childProcId = $procM->create(0, $jobName, '', 10);
         usleep(500);
         if ($procM->getCount($jobName) > 1) {
             // Wait some millisecond to avoid concurent write
             usleep(mt_rand(100, 20000));
             if ($procM->getCount($jobName) > 1) {
                 $procM->delete($childProcId);
                 exit(0);
             }
         }
         echo _('#core#_#18#') . ' ' . $jobName . '.<BR>';
         $proc = new processus($childProcId);
         $procM->update($proc->id, 'running', '2');
         if (file_exists(get_ini('UPLOAD_FOLDER') . 'running/' . $jobName)) {
             unlink(get_ini('UPLOAD_FOLDER') . 'running/' . $jobName);
         }
         rename(get_ini('UPLOAD_FOLDER') . 'queue/' . $jobName, get_ini('UPLOAD_FOLDER') . 'running/' . $jobName);
         // Get header data
         $item_XML = $domXmlFile->getElementsByTagName('XML')->item(0);
         $item_HEADER = $item_XML->getElementsByTagName('HEADER')->item(0);
         $item_DATA = $item_XML->getElementsByTagName('DATA')->item(0);
         // Set timeout both on execution script and in the database
         set_time_limit($item_HEADER->getElementsByTagName('TIMEOUT')->item(0)->nodeValue);
         $q0 = get_link()->prepare('UPDATE ' . get_ini('BDD_PREFIX') . 'core_processus SET timeout=:timeout WHERE id=:id');
         $q0->execute(array('timeout' => $item_HEADER->getElementsByTagName('TIMEOUT')->item(0)->nodeValue, 'id' => $proc->id));
         // Include the file we need
         $g = $item_HEADER->getElementsByTagName('PLUGIN')->item(0)->nodeValue;
         $p = $item_HEADER->getElementsByTagName('PAGE')->item(0)->nodeValue;
Esempio n. 2
0
<?php

if (isset($argv[3])) {
    $processId = $argv[3];
} elseif (isset($_POST['processId'])) {
    $processId = $_POST['processId'];
} elseif (isset($_GET['processId'])) {
    $processId = $_GET['processId'];
} else {
    echo 'There is no pid to process.';
    exit(1);
}
// Build the proc class for this process
$procM = new processusManager();
$proc = new processus($processId);
$procM->update($proc->id, 'running', 1);
// Wait 500ms before moving the processing file
usleep(500000);
if (file_exists(get_ini('UPLOAD_FOLDER') . 'running/' . $proc->cmd)) {
    unlink(get_ini('UPLOAD_FOLDER') . 'running/' . $proc->cmd);
}
rename(get_ini('UPLOAD_FOLDER') . 'queue/' . $proc->cmd, get_ini('UPLOAD_FOLDER') . 'running/' . $proc->cmd);
// Valid the xml file with XSD
$domXmlFile = new DOMDocument();
$domXmlFile->preserveWhiteSpace = false;
$domXmlFile->Load(get_ini('UPLOAD_FOLDER') . 'running/' . $proc->cmd);
if ($domXmlFile->schemaValidate('plugins/core/xsd/core.xsd')) {
    // Get header data
    $item_XML = $domXmlFile->getElementsByTagName('XML')->item(0);
    $item_HEADER = $item_XML->getElementsByTagName('HEADER')->item(0);
    $item_DATA = $item_XML->getElementsByTagName('DATA')->item(0);
Esempio n. 3
0
 $procM = new processusManager();
 $procId = $procM->create(0, get_ini('PROCESS_NAME'), '', time() + get_ini('PROCESS_LIFE_TIME'));
 $proc = new processus($procId);
 echo date('Y-m-d H:i:s') . ' - Runner loaded - process id: ' . $proc->id . "\n";
 $lastCollectorTime = 0;
 while ($endTime > time()) {
     // Check if another process don't kill this process
     $q0 = get_link()->prepare("SELECT status AS PROCESSSTATUS FROM " . get_ini('BDD_PREFIX') . "core_processus WHERE id = :id AND status = 'failed'");
     $q0->execute(array('id' => $proc->id));
     $r0 = $q0->fetch(PDO::FETCH_OBJ);
     if (isset($r0->PROCESSSTATUS)) {
         echo date('Y-m-d H:i:s') . ' - Another process kill me.' . "\n";
         exit(0);
     }
     // Update process status
     $procM->update($proc->id, 'running', floor((time() - $beginTime) * 100 / ($endTime - $beginTime)));
     // Collector task / Limit run to avoid to much I/O
     if ($lastCollectorTime < time() - get_ini('COLLECTOR_POLLING')) {
         echo date('Y-m-d H:i:s') . ' - Runner load the collector' . "\n";
         // Delete old not ended process
         $q0 = get_link()->prepare('UPDATE ' . get_ini('BDD_PREFIX') . 'core_processus SET status=:status, deleted_date=:deleted_date, deleted_id=:deleted_id WHERE timeout < :current_date AND deleted_date = 0');
         $q0->execute(array('status' => 'failed', 'current_date' => time(), 'deleted_id' => $_SESSION['USER_ID'], 'deleted_date' => time()));
         // TODO - select => while => $procM->delete à la place du bloc ci dessus
         // Delete old process
         $q0 = get_link()->prepare('DELETE FROM ' . get_ini('BDD_PREFIX') . 'core_processus WHERE deleted_date < :delete_date AND deleted_date > 0');
         $q0->execute(array('delete_date' => time() - get_ini('DELETED_PROCESS_LIFE_TIME')));
         // Delete old file
         $folder = new DirectoryIterator(get_ini('UPLOAD_FOLDER') . 'running/');
         foreach ($folder as $file) {
             if ($file->isFile() && !$file->isDot() && time() - $file->getMTime() > get_ini('UPLOAD_RUNNING_FILE_LIFE')) {
                 unlink($file->getPathname());