/** * Returns the statuses of machines in the machine table of their * fetchers and queue_server as well as the name and url's of these machines * * @param array $machines an array of machines to check the status for * @return array a list of machines, together with all their properties * and the statuses of their fetchers and queue_servers */ function getMachineStatuses($machines = array()) { $num_machines = count($machines); $time = time(); $session = md5($time . AUTH_KEY); for ($i = 0; $i < $num_machines; $i++) { $hash_url = crawlHash($machines[$i]["URL"]); $machines[$i][CrawlConstants::URL] = $machines[$i]["URL"] . "?c=machine&a=statuses&time={$time}" . "&session={$session}&arg={$hash_url}"; } $statuses = FetchUrl::getPages($machines); for ($i = 0; $i < $num_machines; $i++) { foreach ($statuses as $status) { if ($machines[$i][CrawlConstants::URL] == $status[CrawlConstants::URL]) { $pre_status = json_decode($status[CrawlConstants::PAGE], true); if (is_array($pre_status)) { $machines[$i]["STATUSES"] = $pre_status; } else { $machines[$i]["STATUSES"] = "NOT_CONFIGURED_ERROR"; } } } } $sql = "SELECT * FROM ACTIVE_FETCHER"; $result = $this->db->execute($sql); if (!$result) { return $machines; } $active_fetchers = array(); while ($row = $this->db->fetchArray($result)) { for ($i = 0; $i < $num_machines; $i++) { if ($machines[$i]['NAME'] == $row['NAME']) { if (!isset($machines[$i]["STATUSES"]["fetcher"][$row['FETCHER_ID']])) { $machines[$i]["STATUSES"]["fetcher"][$row['FETCHER_ID']] = 0; } } } } stringROrderCallback("", "", "NAME"); if ($machines != array()) { usort($machines, "stringROrderCallback"); } $name_server_statuses = CrawlDaemon::statuses(); $machines['NAME_SERVER']['news_updater'] = 0; if (isset($name_server_statuses['news_updater'])) { $machines['NAME_SERVER']['news_updater'] = 1; } return $machines; }
/** * Used to start/stop a queue_server/fetcher of the current Yioop instance * based on the queue_server and fetcher fields of the current $_REQUEST */ function update() { $statuses = CrawlDaemon::statuses(); if (isset($_REQUEST['queue_server'])) { if ($_REQUEST['queue_server'] == "true" && !isset($statuses["queue_server"][-1])) { CrawlDaemon::start("queue_server", 'none', self::INDEXER, 0); CrawlDaemon::start("queue_server", 'none', self::SCHEDULER, 2); } else { if ($_REQUEST['queue_server'] == "false" && isset($statuses["queue_server"][-1])) { CrawlDaemon::stop("queue_server"); } } } if (isset($_REQUEST['mirror'])) { if ($_REQUEST['mirror'] == "true" && !isset($statuses["mirror"][-1])) { CrawlDaemon::start("mirror"); } else { if ($_REQUEST['mirror'] == "false" && isset($statuses["mirror"][-1])) { CrawlDaemon::stop("mirror"); } } } if (isset($_REQUEST['fetcher']) && is_array($_REQUEST['fetcher'])) { foreach ($_REQUEST['fetcher'] as $index => $value) { if ($value == "true" && !isset($statuses["fetcher"][$index])) { CrawlDaemon::start("fetcher", "{$index}"); } else { if ($value == "false" && isset($statuses["fetcher"][$index])) { CrawlDaemon::stop("fetcher", "{$index}"); } } } } }