/** * 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 }
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; }
function function_reduce($job) { global $objWorker; $arrData = $objWorker->getNotifyData($job); //Get class $className = $arrData['class']; //Get function $function = $arrData['function']; if (!($className && $function)) { var_dump($className, $function); echo 'not class and function 1'; return true; } //check params $args = $arrData['args']; try { Thethao_Global::closeResource(); //close resource cache central $result = call_user_func_array(array($className, $function), array($args)); if ($result === NULL) { var_dump($className, $function); echo 'not class, function or return null '; } Thethao_Global::closeResource(); $logfile = realpath(dirname(__FILE__)) . '/logs/fontend-' . $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"; echo "====>Result execute :" . Zend_Json::encode($result); $logger->log($logdata, Zend_Log::INFO); } catch (Exception $ex) { print_r($ex); return false; } return true; }
/** * 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); }
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(); }