示例#1
0
文件: fetcher.php 项目: yakar/yioop
 /**
  * Get status, current crawl, crawl order, and new site information from
  * the queue_server.
  *
  * @return mixed array or bool. If we are doing
  *     a web crawl and we still have pages to crawl then true, if the
  *     scheduler page fails to download then false, otherwise, returns
  *     an array of info from the scheduler.
  */
 function checkScheduler()
 {
     $prefix = $this->fetcher_num . "-";
     $info = array();
     $to_crawl_count = count($this->to_crawl);
     $to_crawl_again_count = count($this->to_crawl_again);
     if ($this->recrawl_check_scheduler) {
         crawlLog("Archive Crawl checking ... Recrawl.");
     }
     if ((count($this->to_crawl) > 0 || count($this->to_crawl_again) > 0) && !$this->recrawl_check_scheduler) {
         crawlLog("  Current to crawl count:" . $to_crawl_count);
         crawlLog("  Current to crawl try again count:" . $to_crawl_again_count);
         crawlLog("So not checking scheduler.");
         return true;
     }
     $this->selectCurrentServerAndUpdateIfNeeded(false);
     $this->recrawl_check_scheduler = false;
     $queue_server = $this->queue_servers[$this->current_server];
     crawlLog("Checking  {$queue_server} for a new schedule.");
     // hosts with error counts cleared with each schedule
     $this->hosts_with_errors = array();
     $start_time = microtime();
     $time = time();
     $session = md5($time . AUTH_KEY);
     $request = $queue_server . "?c=fetch&a=schedule&time={$time}&session={$session}" . "&robot_instance=" . $prefix . ROBOT_INSTANCE . "&machine_uri=" . WEB_URI . "&crawl_time=" . $this->crawl_time . "&check_crawl_time=" . $this->check_crawl_time;
     $info_string = FetchUrl::getPage($request, NULL, true);
     crawlLog("Making schedule request: " . $request);
     if ($info_string === false) {
         crawlLog("The request failed!!!!");
         return false;
     }
     $info_string = trim($info_string);
     $tok = strtok($info_string, "\n");
     $info = unserialize(base64_decode($tok));
     $this->setCrawlParamsFromArray($info);
     if (isset($info[self::SITES])) {
         $tok = strtok("\n");
         //skip meta info
         $this->to_crawl = array();
         while ($tok !== false) {
             $string = base64_decode($tok);
             $weight = unpackFloat(substr($string, 0, 4));
             $delay = unpackInt(substr($string, 4, 4));
             $url = substr($string, 8);
             $this->to_crawl[] = array($url, $weight, $delay);
             $tok = strtok("\n");
         }
         $dir = CRAWL_DIR . "/schedules";
         file_put_contents("{$dir}/{$prefix}" . self::fetch_batch_name . "{$this->crawl_time}.txt", serialize($this->to_crawl));
         $this->db->setWorldPermissionsRecursive("{$dir}/{$prefix}" . self::fetch_batch_name . "{$this->crawl_time}.txt");
         unset($info[self::SITES]);
         file_put_contents("{$dir}/{$prefix}" . self::fetch_crawl_info . "{$this->crawl_time}.txt", serialize($info));
     }
     crawlLog("Time to check Scheduler " . changeInMicrotime($start_time));
     return $info;
 }
 function get_from_spr($data)
 {
     $pos = 0;
     //кол-во байт в типе стали (ищем первое вхождение нулевого байта)
     $steelTypeByteCount = strpos($data, "");
     // класс стали
     $this->steel_type = substr($data, 0, $steelTypeByteCount);
     $pos += 80;
     // Тип группы
     $this->group_type = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // Тип элемента
     $this->member_type = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // Нулевые байты
     $pos += 3;
     // Коэффициент расчетной длины отличается от нормативных
     $this->isMuSameWithRegulation = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // 00 - расчетные длины, 01 - коэффициенты расчетной длины
     $this->isMuUsed = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // Неупругая работа (0 - нет, 1 - да)
     $this->isOnlyElastic = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // сопротивление стали
     $this->steel_Ry = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     //gamma_N
     $this->gamma_n = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     //gamma_C
     $this->gamma_c = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     // Нулевые байты
     $pos += 8;
     // Коэффициенты расчетной длины
     $this->mu_XZ = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     $this->mu_XY = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     // Гибкости
     $this->flexCompressed = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     $this->flexTensed = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     // Расстояние между точками раскрепления
     $this->bucklingDistance = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     // Нулевые байты
     $pos += 16;
     // Расчетные длины
     $this->length_XZ = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     $this->length_XY = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     // Неизвестные значения
     $this->noname1 = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     $this->noname2 = unpackDouble(substr($data, $pos, 8));
     $pos += 8;
     // Нулевые байты
     $pos += 8;
     // Проверка перемещений от всех нагрузок (0 - да, 1 - нет)
     $this->deflectionFromAllLoadsToBeChecked = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // Проверка перемещений от временных нагрузок (0 - да, 1 - нет)
     $this->deflectionFromTemporaryLoadsToBeChecked = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // Нулевые байты
     $pos += 32;
     // Предельные относительные перемещения
     $this->limitRelativeDisplacementFromAllLoads = unpackFloat(substr($data, $pos, 4));
     $pos += 4;
     $this->limitRelativeDisplacementFromTemporaryLoads = unpackFloat(substr($data, $pos, 4));
     $pos += 4;
     // Нулевые байты
     $pos += 22;
     // Дополнительная группа (0 - нет, 1 - да)
     $this->isGroupAdditional = unpackInt_1(substr($data, $pos, 1));
     $pos += 1;
     // Нулевые байты
     $pos += 40;
     // Предельные абсолютные перемещения
     $this->limitAbsoluteDisplacementFromAllLoads = unpackFloat(substr($data, $pos, 4));
     $pos += 4;
     $this->limitAbsoluteDisplacementFromTemporaryLoads = unpackFloat(substr($data, $pos, 4));
     $pos += 4;
 }