Ejemplo n.º 1
0
 /**
  * this func is use for master server: write hcm only
  * @param string $keyMemcache
  * @param array $arrData
  * @param string $strFarmName
  * @return boolean|array
  * @author PhuongTN
  */
 public static function writeMemcache($keyMemcache, $arrData, $strFarmName = 'all', $strShading = NULL, $intTime = 0)
 {
     try {
         $writeRS = false;
         //get memcache ins
         $objCache = Thethao_Global::getCache($strFarmName, $strShading, 'hcm');
         //write key cache
         $writeRS = $objCache->write($keyMemcache, $arrData, $intTime);
     } catch (Exception $ex) {
         //log error
         Thethao_Global::sendLog($ex);
     }
     return $writeRS;
 }
Ejemplo n.º 2
0
 public function predictAction()
 {
     //get common info of match
     $this->_getInfoMatch();
     // Disable render layout
     $this->_helper->layout->disableLayout(true);
     $this->_helper->viewRenderer->setNoRender(true);
     // Get user login
     $session = new Zend_Session_Namespace(SESSION_NAMESPACE);
     $arrParams = $this->_request->getParams();
     $intMatchID = (int) $arrParams['matchid'] ? $arrParams['matchid'] : 0;
     $intGoalTeam1 = (int) $arrParams['goalteam1'] ? $arrParams['goalteam1'] : 0;
     $intGoalTeam2 = (int) $arrParams['goalteam2'] ? $arrParams['goalteam2'] : 0;
     //get site id
     $client_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     // Prepare for reading cache
     $memcacheInstance = Thethao_Global::getCache();
     $keyCache = vsprintf(CACHING_PREFIX . 'client_ip:%s:%s', array($intMatchID, $client_ip));
     //get memcache
     $predict = $memcacheInstance->read($keyCache);
     if ($predict === false) {
         //Check matchID
         if (!$intMatchID) {
             echo -1;
             return;
         }
         //Check input data
         if ($intGoalTeam1 < 0 || $intGoalTeam2 < 0) {
             echo -2;
             return;
         }
         $params = array('match_id' => $intMatchID, 'mobile' => NULL, 'userid' => (int) $session->userid, 'goal_team1' => (int) $arrParams['goalteam1'], 'goal_team2' => (int) $arrParams['goalteam2'], 'numpeople' => NULL, 'codepre' => NULL, 'type' => 1);
         //Insert predict
         $matchModel = Thethao_Model_Match::getInstance();
         $arrReponse = $matchModel->pushJobInsertMatchPredict($params);
         // Write to cache
         if ($arrReponse) {
             $memcacheInstance->write($keyCache, $arrReponse, 60);
             Thethao_Global::writeMemcache($keyCache, $arrReponse, 'all', NULL, 60);
         }
         echo Zend_Json::encode($arrReponse);
     } else {
         echo -1;
         return;
     }
 }
Ejemplo n.º 3
0
 /**
  * Get list players by team
  * @param int $teamId
  * @return array
  * @author ThuyNT
  */
 public function getListPlayersByTeam($teamId)
 {
     $memcacheInstance = Thethao_Global::getCache();
     $keyCache = vsprintf($this->_player_by_team, array($teamId));
     // Read from cache
     $arrListPlayers = $memcacheInstance->read($keyCache);
     // Miss cache
     if ($arrListPlayers === FALSE) {
         try {
             // Get application's configuation
             $config = Thethao_Global::getApplicationIni();
             // Get mysql object access player
             $playerMysqlObj = $this->factory('Player', $config['database']['default']['adapter']);
             // Get data from db
             $arrListPlayers = $playerMysqlObj->getListPlayersByTeam($teamId);
             if (!empty($arrListPlayers)) {
                 // Write to cache
                 $memcacheInstance->write($keyCache, $arrListPlayers);
                 Thethao_Global::writeMemcache($keyCache, $arrListPlayers);
             } else {
                 // Store into cache
                 $memcacheInstance->write($keyCache, -1);
                 Thethao_Global::writeMemcache($keyCache, -1);
             }
         } catch (Exception $ex) {
             Thethao_Global::sendlog($ex, 1);
         }
     } else {
         if ($arrListPlayers == -1) {
             $arrListPlayers = array();
         }
     }
     return $arrListPlayers;
 }
Ejemplo n.º 4
0
 /**
  * Get Article Id By Product Id
  * @param int $intId
  * @return $articleId
  * @author HungNT1
  * @todo Thethao
  */
 public function getArticleIdByProductId($intId)
 {
     try {
         //get memcache instance
         $memcached = Thethao_Global::getCache('all');
         //make key cache
         $keyCache = vsprintf($this->_map_article, array($intId));
         //get cache
         $articleId = $memcached->read($keyCache);
         if ($articleId == false) {
             //get config
             $config = Thethao_Global::getApplicationIni();
             //get db instance
             $newsMysql = $this->factory('News', $config['database']['default']['adapter']);
             //call sp to get article id by product id, return array
             $articleId = $newsMysql->getArticleIdByProductId($intId);
             if (count($articleId) > 0) {
                 //Wire question answer cache here!
                 $memcached->write($keyCache, $articleId, 43200);
             } else {
                 $memcached->write($keyCache, -1, 43200);
             }
         }
         //end check if miss cache
         return $articleId;
     } catch (Exception $ex) {
         //log error
         Thethao_Global::sendLog($ex);
     }
 }
Ejemplo n.º 5
0
 /**
  * Function rewrite match cache for football Live
  */
 public function rewriteMatchLive($params)
 {
     $modelObject = new Fpt_Data_Materials_Object();
     $arrMatch = array();
     // Execute data match
     if (isset($params['match']) && !empty($params['match'])) {
         $memcacheInstance = Thethao_Global::getCache();
         foreach ($params['match'] as $id => $match) {
             //add match id=>time-happen
             $arrMatch[$id] = $match['time_happen'];
             if (!empty($match['player'])) {
                 $keyCache1 = vsprintf($this->_player_team_match_list, array($id, $match['team1_id']));
                 $keyCache2 = vsprintf($this->_player_team_match_list, array($id, $match['team2_id']));
                 Thethao_Global::deleteMemcache(array($keyCache1, $keyCache2));
                 $arrPlayersTeamHome = $match['player'][$match['team1_id']];
                 $arrPlayersTeamAway = $match['player'][$match['team2_id']];
                 $memcacheInstance->write($keyCache1, $arrPlayersTeamHome);
                 Thethao_Global::writeMemcache($keyCache1, $arrPlayersTeamHome);
                 $memcacheInstance->write($keyCache2, $arrPlayersTeamAway);
                 Thethao_Global::writeMemcache($keyCache2, $arrPlayersTeamAway);
             }
             if (isset($match['Event']) && !empty($match['Event'])) {
                 $keyMatchDetail = vsprintf($this->_match_extend, '');
                 //set extend match detail
                 $keyMatchDetail = $keyMatchDetail . $id;
                 Thethao_Global::deleteMemcache(array($keyMatchDetail));
                 //write cache memcache
                 $memcacheInstance->write($keyMatchDetail, $match['Event']);
                 Thethao_Global::writeMemcache($keyMatchDetail, $match['Event']);
             }
             //update detail match
             if (isset($match['Result']) && $match['Result']) {
                 $modelObject->getMatch()->updateObject($id, true);
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Get list league by group
  * @param int $group
  * @return array
  */
 public function getListLeagueByGroup($group)
 {
     $memcacheInstance = Thethao_Global::getCache();
     $keyCache = vsprintf($this->_league_by_group_list, array($group));
     // Read cache
     $listLeagues = $memcacheInstance->read($keyCache);
     // Miss cache
     if ($listLeagues === FALSE) {
         try {
             $config = Thethao_Global::getApplicationIni();
             // Get db teamseason instance
             $leagueObj = $this->factory('Football', $config['database']['default']['adapter']);
             // Get data from db
             $listLeagues = $leagueObj->getListLeagueByGroup($group);
             // Write to cache
             $memcacheInstance->write($keyCache, $listLeagues);
             Thethao_Global::writeMemcache($keyCache, $listLeagues);
         } catch (Exception $ex) {
             Thethao_Global::sendlog($ex);
         }
     }
     return $listLeagues;
 }
Ejemplo n.º 7
0
 /**
  * Get full category include all sub category
  * @return array
  * @author LamTX
  */
 public function getFullCategoryByParentId($preCache = false)
 {
     if ($this->_cate == null) {
         $intCategoryID = SITE_ID;
         // Get instance memcache
         $memcacheInstance = Thethao_Global::getCache();
         $keyCache = vsprintf($this->_key_cache, array($intCategoryID));
         // Get full category from Memcache
         $arrMenuCate = $memcacheInstance->read($keyCache);
         //$arrFullCatInfo = array();
         // Data not in cache
         if ($preCache || empty($arrMenuCate['menu']) && empty($arrMenuCate['cate'])) {
             // Get application config
             $config = Thethao_Global::getApplicationIni();
             // Get instance mysql
             $cateMysql = $this->factory('Category', $config['database']['default']['adapter']);
             $arrMenuCate = array('menu' => array(), 'cate' => array());
             // Get cate in DB
             $arrFullCatInfo = $cateMysql->getFullCategoryByParentId($intCategoryID);
             if (!empty($arrFullCatInfo)) {
                 $arrTemp = array();
                 foreach ($arrFullCatInfo as $detail) {
                     $detail['child'] = $detail['child_recursive'] = array();
                     //update cate share_url
                     if ($detail['parent_id'] == SITE_ID) {
                         switch ($detail['category_id']) {
                             case CATE_ID_VIDEO:
                             case CATE_ID_PHOTO:
                             case CATE_ID_FIXTURE:
                                 $detail['link'] = '/' . $detail['catecode'];
                                 break;
                             case SITE_ID:
                                 $detail['link'] = '/';
                                 break;
                             default:
                                 $detail['link'] = '/tin-tuc/' . $detail['catecode'];
                                 break;
                         }
                     } else {
                         //check world cup
                         if ($detail['parent_id'] == WORLD_CUP || $detail['parent_id'] == SEA_GAMES) {
                             $detail['link'] = '/' . $detail['catecode'];
                         } else {
                             $detail['link'] = $arrTemp[$detail['parent_id']]['link'] . '/' . $detail['catecode'];
                         }
                     }
                     //end if
                     //explode parent => array
                     $detail['full_parent'] = $detail['full_parent_original'] = explode(',', $detail['full_parent']);
                     //remove site_id
                     unset($detail['full_parent'][0]);
                     //pre order key
                     $detail['full_parent'] = array_values($detail['full_parent']);
                     //assign array temp
                     $arrTemp[$detail['category_id']] = $detail;
                     //update share_url + parent to original array
                     $arrFullCatInfo[$detail['category_id']] = $detail;
                     //if this cate have parent
                     if (!empty($arrTemp[$detail['category_id']]['full_parent_original'])) {
                         foreach ($arrTemp[$detail['category_id']]['full_parent_original'] as $intParentId) {
                             //if not SITE_ID (cate_id=parent_id)
                             if ($intParentId != $detail['category_id']) {
                                 //update child
                                 $arrTemp[$intParentId]['child_recursive'][] = $detail['category_id'];
                                 $arrFullCatInfo[$intParentId]['child_recursive'][] = $detail['category_id'];
                             }
                             //end if
                         }
                         //end foreach
                         //update current cate child list
                         if ($intParentId != $detail['category_id']) {
                             $arrTemp[$detail['parent_id']]['child'][$detail['category_id']] = $detail;
                             $arrFullCatInfo[$detail['parent_id']]['child'][] = $detail['category_id'];
                         }
                         //end if
                     }
                     //end if
                 }
                 //end foreach
                 //format output
                 $arrMenuCate['menu'] = array(SITE_ID => $arrTemp[SITE_ID]);
                 $arrMenuCate['cate'] = $arrFullCatInfo;
                 //wriet memcache
                 $memcacheInstance->write($keyCache, $arrMenuCate);
                 //check from job to write memcached hcm
                 if ($preCache) {
                     Thethao_Global::writeMemcache($keyCache, $arrMenuCate, 'all');
                 }
                 //end if
             }
             //end if
         }
         //end if
         $this->_menu = $arrMenuCate['menu'];
         $this->_cate = $arrMenuCate['cate'];
     }
     //end if
     return $this->_cate;
 }
Ejemplo n.º 8
0
 /**
  * Get tennis table ranking from cache.<br />
  * If miss cache => get data from database and write cache.
  * @param int $gender Only 0 or 1. 0 => woman (WTA), 1 => man (ATP)
  * @param int|NULL $year  If this parameter is NULL, that means current year
  * @return array|boolean
  * @author QuangTM
  */
 public function getTennisTableRanking($gender, $year = NULL)
 {
     // Create validate
     $validInt = new Zend_Validate_Int();
     // Validate gender
     if (!$validInt->isValid($gender) || $gender < 0 || $gender > 1) {
         return FALSE;
     }
     // Standardized year
     $currentYear = intval(date('Y'));
     if ($year == NULL) {
         $year = $currentYear;
     }
     // Validate year
     if (!$validInt->isValid($year) || $year > $currentYear) {
         return FALSE;
     }
     // Create key cache about tennis player
     $keyTableRanking = vsprintf($this->_table_ranking, array($gender, $year));
     // Get memcache instance
     $memcacheInstance = Thethao_Global::getCache();
     // Read data from cache
     $tableRanking = $memcacheInstance->read($keyTableRanking);
     // If miss cache
     if ($tableRanking === FALSE) {
         // Get table ranking from DB
         $tableRanking = $this->_getTennisTableRankingFromDb($gender, $year);
         // Write cache
         if (is_array($tableRanking) && count($tableRanking)) {
             $memcacheInstance->write($keyTableRanking, $tableRanking);
             Thethao_Global::writeMemcache($keyTableRanking, $tableRanking);
         } else {
             $memcacheInstance->write($keyTableRanking, -1);
             Thethao_Global::writeMemcache($keyTableRanking, -1);
         }
     }
     // Return table ranking
     if ($tableRanking == -1) {
         return array('table' => NULL, 'updateTime' => NULL);
     }
     return $tableRanking;
 }
Ejemplo n.º 9
0
 /**
  * Function get data from table keybox by key_box_id
  * @param array $params
  * @return array data
  */
 public function getKeyBox($params)
 {
     try {
         // Build key cache
         $keyCache = Thethao_Global::makeCacheKey($params['key_id']);
         if (!$keyCache) {
             $keyCache = $params['key_id'];
         }
         // Get instance memcache
         $memcacheInstance = Thethao_Global::getCache();
         // Read hot match in memcache
         $arrReturn = $memcacheInstance->read($keyCache);
         //check cache
         if ($arrReturn === FALSE) {
             //get app config
             $config = Thethao_Global::getApplicationIni();
             //get mysql instance
             $mysqlInstance = $this->factory('Block', $config['database']['default']['adapter']);
             // Get data in DB
             $arrReturn = $mysqlInstance->getKeyBox('"' . $params['key_id'] . '"');
             //Decode Json for write memcache
             $arrReturn = Zend_Json::decode($arrReturn[$params['key_id']]);
             if (!empty($arrReturn)) {
                 // Store into cache
                 $memcacheInstance->write($keyCache, $arrReturn);
                 Thethao_Global::writeMemcache($keyCache, $arrReturn);
             } else {
                 // Store into cache
                 $memcacheInstance->write($keyCache, -1);
                 Thethao_Global::writeMemcache($keyCache, -1);
             }
         } else {
             if ($arrReturn == -1) {
                 $arrReturn = array();
             }
         }
     } catch (Exception $ex) {
         //log error
         Thethao_Global::sendLog($ex);
     }
     return $arrReturn;
 }