예제 #1
0
 function mainwp_cronstats_action()
 {
     MainWPLogger::Instance()->info('CRON :: stats');
     MainWPUtility::update_option('mainwp_cron_last_stats', time());
     if (get_option('mainwp_seo') != 1) {
         return;
     }
     $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getWebsitesStatsUpdateSQL());
     $start = time();
     while ($websites && ($website = @MainWPDB::fetch_object($websites))) {
         if ($start - time() > 60 * 60 * 2) {
             //two hours passed, next cron will start!
             break;
         }
         $alexia = MainWPUtility::getAlexaRank($website->url);
         $pageRank = 0;
         //MainWPUtility::getPagerank($website->url);
         $indexed = MainWPUtility::getGoogleCount($website->url);
         MainWPDB::Instance()->updateWebsiteStats($website->id, $pageRank, $indexed, $alexia, $website->pagerank, $website->indexed, $website->alexia);
         if ($website->sync_errors != '') {
             //Try reconnecting
             MainWPLogger::Instance()->infoForWebsite($website, 'reconnect', 'Trying to reconnect');
             try {
                 if (MainWPManageSites::_reconnectSite($website)) {
                     //Reconnected
                     MainWPLogger::Instance()->infoForWebsite($website, 'reconnect', 'Reconnected successfully');
                 }
             } catch (Exception $e) {
                 //Still something wrong
                 MainWPLogger::Instance()->warningForWebsite($website, 'reconnect', $e->getMessage());
             }
         }
         sleep(3);
     }
     @MainWPDB::free_result($websites);
 }