/** * Fetch a new feed. */ private function fetch() { if (!$this->url) { return false; } $this->posted = array(); $this->skipped = array(); $this->duplicate = array(); $this->lastReturned = 0; $this->time = ''; $this->cachedTime = ''; global $idfeedversion; $http = new http_request($this->getFullURL()); $http->set_useragent("EDK IDFeedfetcher " . $idfeedversion); $http->set_timeout(300); //accept gzip encoding $http->set_header('Accept-Encoding: gzip'); if (strpos($http->get_header(), 'Content-Encoding: gzip') !== false) { $this->xml = gzdecode($http->get_content()); } else { $this->xml = $http->get_content(); } if ($http->get_http_code() != 200) { trigger_error("HTTP error " . $http->get_http_code() . " while fetching feed from " . $this->url . $options . ".", E_USER_WARNING); return false; } if ($this->xml) { return true; } else { return false; } }
public static function xajax_req() { // if the xajax call gets aborted, ignore that @ignore_user_abort(true); @set_time_limit(0); $state = config::get('ajcron_running'); if (!is_array($state)) { $state = array(); config::set('ajcron_running', $state); } // check for blocking if (config::get('ajcron_blocking')) { // if there is already something running, give up if (count($state) >= 1) { return; } } // load up our crontasks $jobs = ajcron::parseJobs(); // if there are no jobs just quit if (!count($jobs)) { return; } // see which one should be started now $sorttable = array(); foreach ($jobs as $job) { $sorttable[$job['id']] = $job['nextrun']; } asort($sorttable); foreach ($sorttable as $id => $nextrun) { // this bypasses already running jobs if (isset($state[$id])) { continue; } break; } if (!$id) { // no id found we could run as all are running return; } // set current id to running $state[$id] = 'running'; $currentJob = null; config::set('ajcron_running', $state); foreach ($jobs as $job) { if ($job['id'] == $id) { $currentJob = $job; } } // run the job (finally) $http = new http_request($currentJob['url']); $http->set_timeout(120); $data = $http->get_content(); // job done, clean up // we need to refresh our variable to prevent overwriting of // other running jobs $db = DBFactory::getDBQuery(true); $db->execute('select * from kb3_config where cfg_site=\'' . KB_SITE . '\' and cfg_key=\'ajcron_running\''); $row = $db->getRow(); $state = unserialize($row['cfg_value']); unset($state[$id]); config::set('ajcron_running', $state); // calculate when next to insert ajax ajcron::getNextRuntime(); // testfun! $objResponse = new xajaxResponse(); #$objResponse->Assign("header", "innerHTML", nl2br(var_export($sorttable[key($sorttable)], true))); #sleep(15); return $objResponse; }