/** * Pre-caching for tennis player information.<br /> * 2 case in this function.<br /> * Clear cache after that read from model to write new data into cache. * @param array $params Must has key arrPlayerIds. That is array player id * @author QuangTM */ public static function preCachingTennisPlayer($params) { //set array player id $arrPlayerIds = $params['arrPlayerIds']; //set array player id to NULL $params['arrPlayerIds'] = array(); //array chunk $arrChunk = array_chunk($arrPlayerIds, 10); //loop foreach ($arrChunk as $listId) { //new object framework $modelObject = new Fpt_Data_Materials_Object(); // Get tennis model $tennisModel = new Thethao_Model_Tennis(); $model = $modelObject->getTennis(); foreach ($listId as $playerID) { $model->updateObject($playerID); } //end foreach //precache $params['arrPlayerIds'] = $listId; $tennisModel->preCachingTennisPlayer($params); //close resource Thethao_Global::closeResource(); Fpt_Data_Model::_destruct(); } //end foreach }
/** * Get list article ids by rule 1, set on folder * @param type $arrParams * @return type array * @author HungNT1 */ public function getListArticleIdsByRule1($arrParams) { if (!isset($arrParams['article_type']) || $arrParams['article_type'] == 0) { $arrParams['article_type'] = NULL; } $site_id = $arrParams['category_id'] == SITE_ID ? NULL : SITE_ID; $arrResult = array('total' => 0, 'data' => array()); $arrParams['from_date'] = isset($arrParams['from_date']) ? $arrParams['from_date'] : NULL; $arrParams['to_date'] = isset($arrParams['to_date']) ? $arrParams['to_date'] : NULL; try { // Get DB $db_s = Thethao_Global::getDB('sport', 'slave'); $stmt = $db_s->prepare('CALL sp_getNewsByRule1(:p_siteid, :p_categoryid, :p_articletype, :p_fromdate, :p_todate, :p_offset, :p_LIMIT)'); //Bind param $stmt->bindParam('p_siteid', $site_id); $stmt->bindParam('p_categoryid', $arrParams['category_id']); $stmt->bindParam('p_articletype', $arrParams['article_type'], PDO::PARAM_STR); $stmt->bindParam('p_fromdate', $arrParams['from_date'], PDO::PARAM_INT); $stmt->bindParam('p_todate', $arrParams['to_date'], PDO::PARAM_INT); $stmt->bindParam('p_offset', $arrParams['offset'], PDO::PARAM_INT); $stmt->bindParam('p_LIMIT', $arrParams['limit'], PDO::PARAM_INT); // Fetch result $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $arrResult['data'][$row['article_id']] = $row['score']; } // Close cursor $stmt->closeCursor(); // Query total row $stmt = $db_s->prepare('CALL sp_getTotalByRule1(:p_siteid, :p_categoryid, :p_articletype, :p_fromdate, :p_todate)'); // Bind param $stmt->bindParam('p_siteid', $site_id); $stmt->bindParam('p_categoryid', $arrParams['category_id']); $stmt->bindParam('p_articletype', $arrParams['article_type'], PDO::PARAM_STR); $stmt->bindParam('p_fromdate', $arrParams['from_date'], PDO::PARAM_INT); $stmt->bindParam('p_todate', $arrParams['to_date'], PDO::PARAM_INT); // Exec func $stmt->execute(); // Fetch total $arrResult['total'] = $stmt->fetchColumn(); // Release unset($stmt); } catch (Zend_Exception $ex) { Fpt_Data_Model::sendLog($ex); } return $arrResult; }
function function_reduce($job) { ini_set('memory_limit', '1G'); ini_set('display_errors', 1); global $objWorker; $arrData = $objWorker->getNotifyData($job); //Get class $className = $arrData['class']; //Get function $function = $arrData['function']; if (!($className && $function)) { echo 'not class or function 1"' . $className . '", "' . $function . '"'; return true; } //check params $args = $arrData['args']; try { Fpt_Data_Model::_destruct(); //close resource cache central $result = call_user_func_array(array($className, $function), array($args)); if ($result === NULL) { echo 'not class or function return null"' . $className . '", "' . $function . '"'; } var_dump('===Result===', Zend_Json::encode($result), '______________________________________'); Thethao_Global::closeResource(); Fpt_Data_Model::_destruct(); //close resource cache central /* $logfile = realpath(dirname(__FILE__)) . '/logs/crawler-' . $function . '-' . date("Y-m-d") . '.log'; $logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream($logfile); $logger->addWriter($writer); $logdata = "\n"; $logdata .= "Result execute :" . Zend_Json::encode($result); $logdata .= "\n"; $logdata .= "Execute function: '" . $function . "' at class : '" . $className . "' with params :" . Zend_Json::encode($args) . "\n"; $logger->log($logdata, Zend_Log::INFO);*/ } catch (Exception $ex) { print_r($ex); return false; } return true; }
/** * write log file to send mail * @param Exception $ex * @param int $level * @return null * @author LamTX */ public static function sendLog($ex, $message = '', $trace = '', $errorCode = 0, $intAction = 0) { try { if (APPLICATION_ENV == 'development') { var_dump('<pre><br><br><h2>' . $ex->getMessage() . '<br></h2><br>' . $ex->getTraceAsString() . '<br>'); return; } Fpt_Data_Model::sendLog($ex); } catch (Exception $ex) { return false; } }
/** * Called before Zend_Controller_Front enters its dispatch loop. * @param Zend_Controller_Request_Abstract $request * @author LamTX */ public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { //get z front $front = Zend_Controller_Front::getInstance(); //get dispatch $dispatcher = $front->getDispatcher(); //check can dispatchable or not if (!$dispatcher->isDispatchable($request)) { //redirect error page $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoUrl('http://vnexpress.net/' . (DEVICE_ENV == 1 ? 'm' : '') . 'error.html')->redirectAndExit(); } //set layout for device $layout = DEVICE_ENV == 1 ? 'mobile' : 'default'; $mode_view = $this->getRequest()->getQuery('view'); if ($mode_view == 'instant_article') { $layout = 'instant_article'; } $layoutInstance = Zend_Layout::startMvc(array('layout' => $layout, 'layoutPath' => APPLICATION_PATH . '/layouts/scripts', 'contentKey' => 'content')); $view = $layoutInstance->getView(); $view->setHelperPath(APPLICATION_PATH . '/layouts/helpers'); $config = $this->_frontController->getParam('bootstrap')->getOptions(); $configFW = Fpt_Data_Model::getInstance()->getConfigStatic(); if (isset($configFW['vnexpress']['static'])) { $config['view']['vnecdn']['js'] = $configFW['vnexpress']['static']['js']; $config['view']['vnecdn']['css'] = $configFW['vnexpress']['static']['css']; $config['view']['vnecdn']['libs'] = $configFW['vnexpress']['static']['libs']; $config['view']['vnecdn']['flash'] = $configFW['vnexpress']['static']['flash']; $config['view']['vnecdn']['images'] = $configFW['vnexpress']['static']['images']; } unset($configFW); $view->assign(array('Snippet' => '', 'MenuActive' => true, 'configView' => $config['view'], 'imageSize' => $config['images'][DEVICE_ENV], 'objArticle' => Fpt_Data_News_Article::getInstance(), 'objObject' => Fpt_Data_Materials_Object::getInstance())); }
/** * Rewirte cache player of team * @author HungNT1 * @param type $arrParams - array('teamId'=>arrayPlayerId) */ public function rewritePlayerTeam($arrParams) { if (!empty($arrParams)) { $params = array(); foreach ($arrParams as $teamId => $arrPlayerId) { // Init model Footbal $modelFootball = new Thethao_Model_Player(); $params['TeamID'] = $teamId; $params['arrPlayerId'] = $arrPlayerId; $modelFootball->rewriteListPlayersByTeam($params); //close resource Thethao_Global::closeResource(); Fpt_Data_Model::_destruct(); } //init news instance $caching = Thethao_Model_Caching::getInstance(); $caching->clearCacheFile(); } }
function function_reduce($job) { $time_start = microtime(true); global $objWorker; $arrData = $objWorker->getNotifyData($job); echo "\n ************" . date('Y/m/d H:i:s') . "**************\n"; var_dump($arrData); //Get class $className = $arrData['class']; //Get function $function = $arrData['function']; if (!($className && $function)) { echo 'not class and function'; return true; } //check params $args = $arrData['args']; try { Fpt_Data_Model::_destruct(); //close resource cache central $result = call_user_func_array(array($className, $function), array($args)); if ($result === NULL) { $result = array('success' => 0, 'return null / not class or function'); } else { $returnCode = $result != false ? 1 : 0; $result = array('success' => $returnCode, $result); } //Closed all resource Thethao_Global::closeResource(); Fpt_Data_Model::_destruct(); //close resource cache central $logfile = realpath(dirname(__FILE__)) . '/logs/backend-' . $function . '-' . date("Y-m-d") . '.log'; $logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream($logfile); $logger->addWriter($writer); $logdata = "\n"; $logdata .= "Result execute :" . Zend_Json::encode($result); $logdata .= "\n"; $logdata .= "Execute function: '" . $function . "' at class : '" . $className . "' with params :" . Zend_Json::encode($args) . "\n"; $logger->log($logdata, Zend_Log::INFO); } catch (Exception $ex) { $result = array('success' => 0, $ex->getMessage()); } $end = microtime(true) - $time_start; echo "\n Time:" . $end . ' - ' . date("Y/m/d H:i:s"); echo "\n Memory:" . round(memory_get_usage(true) / 1048576, 2) . " megabytes"; echo "\n Result:"; var_dump($result); }
public function rewriteListPlayersByTeam($arrParams) { $teamId = intval($arrParams['TeamID']); // Delete cache player award $keyCache = vsprintf($this->_player_by_team, array($teamId)); Thethao_Global::deleteMemcache(array($keyCache)); $this->getListPlayersByTeam($teamId); if (isset($arrParams['arrPlayerId']) && !empty($arrParams['arrPlayerId'])) { $atrunk = array_chunk($arrParams['arrPlayerId'], 5); foreach ($atrunk as $trunk) { // call object framework to detete cache $modelObject = new Fpt_Data_Materials_Object(); foreach ($trunk as $playerId) { if ($playerId > 0) { //update cache for player (id player, status to getdetail) $modelObject->getPlayer()->updateObject($playerId, true); } } //close resource Fpt_Data_Model::_destruct(); } } }
/** * Get list match ids by league * @param int $teamID * @param int $beginHappenDateTime * @param int $endHappenDateTime * @param boolean - asort array * @return array|boolean * @author ThuyNT */ public function getMatchIDsByLeague($leagueID, $beginHappenDateTime = NULL, $endHappenDateTime = NULL, $rev = TRUE) { // Default result to return $result = FALSE; $flag = TRUE; try { // Get application config $config = Thethao_Global::getApplicationIni(); //get object redis $matchNosqlInstance = $this->factory('Match', $config['database']['nosql']['adapter']); // Read from redis first $result = $matchNosqlInstance->getListMatchesByHappenTime($leagueID, $beginHappenDateTime, $endHappenDateTime); // If miss cache redis => read from DB if (empty($result['data']) && FROM_JOB == 1) { //get mysql instance $matchMysqlInstance = $this->factory('Match', $config['database']['default']['adapter']); // Read data from MySQL $result = $matchMysqlInstance->getListMatchesByHappenTime($beginHappenDateTime, $endHappenDateTime, $leagueID, $gmt = 0, $flag); //check to set redis if (!empty($result)) { $matchNosqlInstance->setMatchIDsByLeague($leagueID, $result); } $intTotal = count($result); $arrTest = array_values($result); if ($beginHappenDateTime) { for ($i = $intTotal - 1; $i > 0; $i--) { if ($arrTest[$i] >= $beginHappenDateTime) { $result = array_slice($result, 0, $i + 1, true); $i = 0; } } } if ($endHappenDateTime) { for ($i = 0; $i < $intTotal; $i++) { if ($arrTest[$i] <= $endHappenDateTime) { $result = array_slice($result, $i, NULL, true); $i = $intTotal; } } } } else { $result = $result['data']; } if (!$rev && !empty($result)) { asort($result); } } catch (Exception $ex) { Fpt_Data_Model::sendLog($ex); } return $result; }
/** * Get detail player by id * @param int $player_id, $type * @return array|boolean * @author QuangTM */ public function getDetailPlayerByID($player_id, $type) { try { // Get DB Obj $dbObj = Thethao_Global::getDB('sport', 'slave'); $stmt = $dbObj->prepare('Call sp_sport_gePlayerAwardByType(:p_playerid,:p_type);'); // bind params $stmt->bindParam('p_playerid', $player_id, PDO::PARAM_INT); $stmt->bindParam('p_type', $type, PDO::PARAM_INT); // execute $stmt->execute(); //Fetch Result $result = $stmt->fetchAll(); // Close cursor $stmt->closeCursor(); // Release unset($stmt); //Return array return $result; } catch (Exception $ex) { Fpt_Data_Model::sendLog($ex); return FALSE; } }
Zend_Controller_Front::getInstance()->setParam('bootstrap', $application); //unset applicaion unset($application); //Try execute $result = array(); try { //get model news $modelNews = Thethao_Model_News::getInstance(); //get model category $modelCategory = Thethao_Model_Category::getInstance(); //get full array cate $arrCate = $modelCategory->getFullCategoryByParentId(); //only get id $arrCate = array_keys($arrCate); //add site_id $arrCate[] = SITE_ID; //clear cache $result['interaction'] = $modelNews->clearCacheTop('all', $arrCate); //get top view 24h all Site $result['top_view_all_site'] = $modelNews->getTopView24hAllSite(); //Closed all resource Thethao_Global::closeResource(); Fpt_Data_Model::_destruct(); } catch (Exception $ex) { //send log Thethao_Global::sendLog($ex); //Closed all resource Thethao_Global::closeResource(); Fpt_Data_Model::_destruct(); echo $ex->getMessage(); }
/** * Get extend of match detail * @param type $arrMatchId * @return boolean|array */ public function getMatchExtendByIDs($arrMatchId) { $result = array(); try { if (!is_array($arrMatchId) || !count($arrMatchId)) { return FALSE; } $strMatchId = implode(',', $arrMatchId); // Get DB Obj $dbObj = Thethao_Global::getDB('sport', 'slave'); // Prepare SQL $stmt = $dbObj->prepare('CALL sp_fesport_getDetailMatchByIDs(:p_matchids);'); // Bind param $stmt->bindParam('p_matchids', $strMatchId, PDO::PARAM_STR); // Execute $stmt->execute(); while ($row = $stmt->fetch()) { if (!isset($result[$row['match_id']])) { $result[$row['match_id']] = array(); } $result[$row['match_id']] = Zend_Json::decode($row['event']); } // Close $stmt->closeCursor(); // Release variables unset($stmt); } catch (Exception $ex) { Fpt_Data_Model::sendLog($ex); return FALSE; } return $result; }