if (!is_file(get_ini('UPLOAD_FOLDER') . 'queue/' . $job->pluginName . '_' . $job->page . '.xml') && !is_file(get_ini('UPLOAD_FOLDER') . 'running/' . $job->pluginName . '_' . $job->page . '.xml')) { $job->flagRunning(); include 'plugins/' . $job->pluginName . '/task_' . $job->page . '_loader.php'; } } } // List all job to do in the queue folder 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);
// Other system(get_ini('PHP_BIN_FOLDER') . 'php index.php core runner_thread "' . $currentProc . '" &'); } } } // Check queue folder for new file $dir = get_ini('UPLOAD_FOLDER') . 'queue/'; $currentDir = opendir($dir); while ($fileName = readdir($currentDir)) { // Process only the xml files if (is_file($dir . $fileName) && strtolower(substr(strrchr($fileName, '.'), 1, strlen($fileName) - 1)) == 'xml') { $domXmlFile = new DOMDocument(); $domXmlFile->preserveWhiteSpace = false; $domXmlFile->Load(get_ini('UPLOAD_FOLDER') . 'queue/' . $fileName); if ($domXmlFile->schemaValidate('plugins/core/xsd/core.xsd')) { if ($procM->getId($fileName) == 0) { $childProcId = $procM->create($procId, $fileName, '', time() + 3600); $procM->update($childProcId, 'pending', 0); echo date('Y-m-d H:i:s') . ' - Runner add new proc - process id: ' . $childProcId . ' - command: ' . $fileName . "\n"; } } else { // If at the grace time, the file is not compliant with the XSD, put in the trash failed folder if (get_ini('PROCESS_GRACE_PERIODE') < time() - filemtime(get_ini('UPLOAD_FOLDER') . 'queue/' . $fileName)) { rename(get_ini('UPLOAD_FOLDER') . 'queue/' . $fileName, get_ini('UPLOAD_FOLDER') . 'failed/' . $fileName); } } unset($domXmlFile); } } closedir($currentDir); // Wait to avoid CPU over usage