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' => time() + $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; // Get the date $xmlDate = toTime($item_HEADER->getElementsByTagName('DATE')->item(0)->nodeValue); // If the Xsd file exist if (is_file('plugins/' . $g . '/xsd/' . $p . '.xsd') && $domXmlFile->schemaValidate('plugins/' . $g . '/xsd/' . $p . '.xsd') && is_file('plugins/' . $g . '/' . $p . '.php') || !is_file('plugins/' . $g . '/xsd/' . $p . '.xsd') && is_file('plugins/' . $g . '/' . $p . '.php')) { if ($g != 'core' && is_file('plugins/' . $g . '/__functions.php')) { require_once 'plugins/' . $g . '/__functions.php'; } include 'plugins/' . $g . '/' . $p . '.php'; } else { $error = 'XML file is not valid or process file does not exist.'; } } else { $error = 'XML file is not valid.'; } // if ko, archive the file in the failed folder if (isset($error)) { $procM->update($proc->id, 'failed', '100'); $procM->delete(); rename(get_ini('UPLOAD_FOLDER') . 'running/' . $proc->cmd, get_ini('UPLOAD_FOLDER') . 'failed/' . time() . '-' . $proc->cmd); } else { // if ok, archive the file rename(get_ini('UPLOAD_FOLDER') . 'running/' . $proc->cmd, get_ini('UPLOAD_FOLDER') . 'archived/' . time() . '-' . $proc->cmd); $procM->update($proc->id, 'ended', '100'); $procM->delete($proc->id); }
foreach (glob(get_ini('UPLOAD_FOLDER') . "queue/*.xml") as $jobName) { $fileFullPath = str_replace('\\', '/', $jobName); $jobName = substr($jobName, strrpos($jobName, '/') + 1, strlen($jobName) - strrpos($jobName, '/') - 1); // Valid the xml file with XSD $domXmlFile = new DOMDocument(); $domXmlFile->preserveWhiteSpace = false; $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