Пример #1
0
 function keywordPositionCheckerCron($websiteId)
 {
     include_once SP_CTRLPATH . "/searchengine.ctrl.php";
     include_once SP_CTRLPATH . "/report.ctrl.php";
     $reportController = new ReportController();
     $seController = new SearchEngineController();
     $reportController->seList = $seController->__getAllCrawlFormatedSearchEngines();
     // get keywords not to be checked
     $time = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     $sql = "select distinct(keyword_id) from keywordcrontracker kc, keywords k where k.id=kc.keyword_id and k.website_id={$websiteId} and time={$time}";
     $keyList = $this->db->select($sql);
     $excludeKeyList = array(0);
     foreach ($keyList as $info) {
         $excludeKeyList[] = $info['keyword_id'];
     }
     // get keywords needs to be checked
     $sql = "select k.*,w.url from keywords k,websites w where k.website_id=w.id and w.id={$websiteId} and k.status=1";
     $sql .= " and k.id not in(" . implode(",", $excludeKeyList) . ") order by k.name";
     $keywordList = $reportController->db->select($sql);
     $this->debugMsg("Starting keyword position checker cron for website: {$this->websiteInfo['name']}....<br>\n");
     // loop through each keyword
     foreach ($keywordList as $keywordInfo) {
         $reportController->seFound = 0;
         $crawlResult = $reportController->crawlKeyword($keywordInfo, '', true);
         foreach ($crawlResult as $sengineId => $matchList) {
             if ($matchList['status']) {
                 foreach ($matchList['matched'] as $i => $matchInfo) {
                     $remove = $i == 0 ? true : false;
                     $matchInfo['se_id'] = $sengineId;
                     $matchInfo['keyword_id'] = $keywordInfo['id'];
                     $repCtrler = new ReportController();
                     $repCtrler->saveMatchedKeywordInfo($matchInfo, $remove);
                 }
                 $this->debugMsg("Successfully crawled keyword <b>{$keywordInfo['name']}</b> results from " . $reportController->seList[$sengineId]['domain'] . ".....<br>\n");
             } else {
                 $this->debugMsg("Crawling keyword </b>{$keywordInfo['name']}</b> results from " . $reportController->seList[$sengineId]['domain'] . " failed......<br>\n");
             }
         }
         // to implement split cron execution feature
         if (SP_NUMBER_KEYWORDS_CRON > 0 && !empty($crawlResult)) {
             $this->checkedKeywords++;
             if ($this->checkedKeywords == SP_NUMBER_KEYWORDS_CRON) {
                 die("Reached total number of allowed keywords(" . SP_NUMBER_KEYWORDS_CRON . ") in each cron job");
             }
         }
         if (empty($reportController->seFound)) {
             $this->debugMsg("Keyword <b>{$keywordInfo['name']}</b> not assigned to required search engines........\n");
         }
         sleep(SP_CRAWL_DELAY);
     }
 }
Пример #2
0
 function keywordPositionCheckerCron($websiteId)
 {
     include_once SP_CTRLPATH . "/searchengine.ctrl.php";
     include_once SP_CTRLPATH . "/report.ctrl.php";
     $reportController = new ReportController();
     $seController = new SearchEngineController();
     $reportController->seList = $seController->__getAllCrawlFormatedSearchEngines();
     $sql = "select k.*,w.url from keywords k,websites w where k.website_id=w.id and w.id={$websiteId} and k.status=1";
     $sql .= " order by k.name";
     $keywordList = $reportController->db->select($sql);
     $this->debugMsg("Starting keyword position checker cron for website: {$this->websiteInfo['name']}....<br>\n");
     # loop through each keyword
     foreach ($keywordList as $keywordInfo) {
         $reportController->seFound = 0;
         $crawlResult = $reportController->crawlKeyword($keywordInfo);
         foreach ($crawlResult as $sengineId => $matchList) {
             if ($matchList['status']) {
                 foreach ($matchList['matched'] as $i => $matchInfo) {
                     $remove = $i == 0 ? true : false;
                     $matchInfo['se_id'] = $sengineId;
                     $matchInfo['keyword_id'] = $keywordInfo['id'];
                     $reportController->saveMatchedKeywordInfo($matchInfo, $remove);
                 }
                 $this->debugMsg("Successfully crawled keyword <b>{$keywordInfo['name']}</b> results from " . $reportController->seList[$sengineId]['domain'] . ".....<br>\n");
             } else {
                 $this->debugMsg("Crawling keyword </b>{$keywordInfo['name']}</b> results from " . $reportController->seList[$sengineId]['domain'] . " failed......<br>\n");
             }
         }
         if (empty($reportController->seFound)) {
             $this->debugMsg("Keyword <b>{$keywordInfo['name']}</b> not assigned to required search engines........\n");
         }
         sleep(SP_CRAWL_DELAY);
     }
 }