예제 #1
0
function reduceFn($job)
{
    global $worker, $verbose;
    //Get parameters
    $params = $worker->getNotifyData($job);
    var_dump($params);
    //Init logger
    if ($verbose) {
        $logfile = DOCUMENT_ROOT . '/logs/caching-' . $params['function'] . '-' . date("Y-m-d") . '.log';
        $logger = new Zend_Log();
        $writer = new Zend_Log_Writer_Stream($logfile);
        $logger->addWriter($writer);
    }
    //Try execute
    $result = 0;
    try {
        //Get class
        $className = $params['class'];
        //Check class
        if (empty($className)) {
            return false;
        }
        //Get function
        $function = $params['function'];
        //Check function
        if (empty($function)) {
            return false;
        }
        //check params
        $args = $params['args'];
        //Starting execute script
        if (empty($args)) {
            $result = call_user_func_array(array($className, $function));
        } else {
            $result = call_user_func_array(array($className, $function), array($args));
        }
        //Try close
        Thethao_Global::closeDb();
        Thethao_Global::closeCache();
        Thethao_Global::closeRedis();
        Thethao_Global::closeGearmanClient();
        //Debug
        if ($verbose) {
            $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) {
        $logdata = "Error :" . $ex->getMessage();
        $logger->log($logdata, Zend_Log::ERR);
        echo $logdata;
    }
    //Return
    return $result;
}