protected function _dispatch($method, $params = null, $source = null) { $st = microtime(true); $content = $params[0]; $mypre = "{$source}-{$method}"; if ($content->lang == 4) { ServerConfig::setLang('en'); } if ($content->lang == 3) { ServerConfig::setLang('zh'); } CrabTools::mydump($params[0], REQ_DATA_ROOT . $mypre . '.param'); Logger::info("{$source}::{$method}"); try { $ret = parent::_dispatch($method, $params, $source); $parastr = print_r($params, true); $et = microtime(true); $cost = $et - $st; $cost = ceil(1000000 * $cost); Logger::info("{$source}::{$method} {$cost} , [{$ret['status']}] [{$ret['msg']}] {$parastr}"); CrabTools::myprint($ret, REQ_DATA_ROOT . $mypre . '.resp'); return $ret; } catch (Exception $e) { CrabTools::myprint($e, REQ_DATA_ROOT . $mypre . '.exp'); return array('status' => 'error', 'msg' => 'exe exception'); } Logger::error('Method "' . $method . '" auth failed' . " sk={$session_key} platform_id={$platform_id} "); return array('status' => 'error', 'msg' => 'auth failed'); }
protected function _handle(&$req) { //just add method map here $method = $req['m']; $mypre = $method; if ($this->_debug) { CrabTools::mydump($req['p'], REQ_DATA_ROOT . $mypre . '.param'); } if (isset(self::$exist_methods[$method])) { $caller =& self::$exist_methods[$method]; $c =& $caller[0]; $m = $caller[1]; } else { $caller = explode('.', $method); $cn = $caller[0]; $m = $caller[1]; $file = CONTROLLER_ROOT . "{$cn}.php"; if (!file_exists($file)) { throw new JsonServerExecption("method {$method} file not exist:(" . CONTROLLER_ROOT . "{$cn}.php)"); } @(require_once $file); $c = new $cn(); if (!method_exists($c, $m)) { throw new JsonServerExecption("{$cn} don't has callable method {$m}"); } } $log_method = array('Achieve.finish' => 1, 'Advert.buy' => 1, 'Advert.set' => 1, 'Cinema.enter' => 1, 'Cinema.pick' => 1, 'Gift.send' => 1, 'Gift.accept' => 1, 'Man.update' => 1, 'UserController.update_friends' => 1, 'UserController.enlarge_mall' => 1, 'ItemController.buy' => 1, 'ItemController.sale' => 1, 'CarController.buy' => 1, 'CarController.sale' => 1, 'CarController.go_goods' => 1, 'CarController.enlarge_garage' => 1, 'CarController.buy_copolit' => 1, 'CarController.apply_copolit' => 1, 'GoodsController.checkout' => 1, 'Task.share' => 1, 'Task.request' => 1, 'Task.accept' => 1, 'Task.update' => 1, 'Task.finish' => 1, 'Task.get_award' => 1, 'Friend.dis_neighbor' => 1, 'HelpGet.award' => 1); try { $ret = $c->{$m}($req['p']); } catch (Exception $e) { $r['s'] = 'exc'; $r['msg'] = $e->getMessage(); $r['exce'] = $e->getTrace(); error_log($method . ':' . $r['msg']); TTLog::record(array('s' => $ret['s'], 'm' => $method, 'tm' => $_SERVER['REQUEST_TIME'], 'p' => $this->_raw_reg)); } if ($this->_debug) { CrabTools::myprint($ret, REQ_DATA_ROOT . $mypre . '.resp'); } if (!$ret) { $ret['s'] = "KO"; $ret['msg'] = "{$cn}::{$m} return null"; TTLog::record(array('s' => 'rnull', 'm' => $method, 'tm' => $tm, 'p' => $this->_raw_reg)); } $tm = $_SERVER['REQUEST_TIME']; if ($ret['s'] == 'OK') { if (array_key_exists($method, $log_method)) { TTLog::record(array('s' => 'OK', 'm' => $method, 'tm' => $tm, 'p' => $this->_raw_reg)); } } //else{ // TTLog::record(array('s'=>$ret['s'],'m'=>$method,'tm'=>$tm,'p'=>$this->_raw_reg)); //} return $ret; }
protected function _handle(&$req) { //just add method map here $method = $req['m']; $mypre = $method; if ($this->_debug) { CrabTools::mydump($req['p'], REQ_DATA_ROOT . $mypre . '.param'); } if (isset(self::$exist_methods[$method])) { $caller =& self::$exist_methods[$method]; $c =& $caller[0]; $m = $caller[1]; } else { $caller = explode('.', $method); $cn = $caller[0]; $m = $caller[1]; $file = CONTROLLER_ROOT . "{$cn}.php"; if (!file_exists($file)) { throw new JsonServerExecption("method {$method} file not exist:(" . CONTROLLER_ROOT . "{$cn}.php)"); } @(require_once $file); $c = new $cn(); if (!method_exists($c, $m)) { throw new JsonServerExecption("{$cn} don't has callable method {$m}"); } } $log_method = array('Achieve.get' => 1, 'Achieve.finish' => 1, 'Advert.buy' => 1, 'Advert.set' => 1, 'Cinema.enter' => 1, 'Cinema.pick' => 1, 'Gift.send' => 1, 'Gift.accept' => 1, 'Man.update' => 1, 'UserController.login' => 1, 'UserController.precheckout' => 1, 'UserController.update_friends' => 1, 'UserController.enlarge_mall' => 1, 'ItemController.buy' => 1, 'ItemController.sale' => 1, 'CarController.buy' => 1, 'CarController.sale' => 1, 'CarController.go_goods' => 1, 'CarController.enlarge_garage' => 1, 'GoodsController.buy' => 1, 'GoodsController.remove' => 1, 'GoodsController.exhibit_goods' => 1, 'GoodsController.checkshop' => 1, 'GoodsController.checkout' => 1, 'TaskController.share' => 1, 'TaskController.request' => 1, 'TaskController.accept' => 1, 'TaskController.update' => 1, 'TaskController.finish' => 1, 'TaskController.get_award' => 1, 'Friend.dis_neighbor' => 1, 'Friend.invite_neighbor' => 1, 'Friend.accept_neighbor' => 1); $ret = $c->{$m}($req['p']); if ($this->_debug) { CrabTools::myprint($ret, REQ_DATA_ROOT . $mypre . '.resp'); } if (!$ret) { $ret['s'] = "KO"; $ret['msg'] = "{$cn}::{$m} return null"; } if ($ret['s'] == 'OK') { if (array_key_exists($method, $log_method)) { TTLog::record(array('m' => $method, 'p' => json_encode($params))); } } return $ret; }
<?php $st = microtime(true); require_once '../base.php'; try { // require_once CONTROLLER_ROOT.'UserController.php'; $server = get_server(); $server->setProduction(false); $server->addDirectory(CONTROLLER_ROOT); //$server->setClass('UserController'); $response = $server->handle(); echo $response; $et = microtime(true); $cost = $et - $st; $cost = ceil(1000000 * $cost) . " us"; CrabTools::myprint($cost, RES_DATA_ROOT . "/{$et}.process_time"); } catch (Exception $e) { CrabTools::mydump($e, RES_DATA_ROOT . '/handler.exception'); CrabTools::mydump($server, RES_DATA_ROOT . '/server.obj'); CrabTools::mydump($response, RES_DATA_ROOT . '/response.str'); }
protected function _handle(&$req) { //just add method map here $tm = $_SERVER['REQUEST_TIME']; $method = $req['m']; $mypre = $method; $log_nok = false; if (array_key_exists($method, self::$log_NOK_methods)) { $log_nok = true; } $req['p']['_cid'] = $req['cid']; $u = $req['p']['u']; if (!$log_nok) { if (check_dup($u, $req['cid'], $ret)) { TTLog::record(array('s' => 'dup', 'm' => $method, 'tm' => $tm, 'u' => $u, 'p' => $this->_raw_reg)); return $ret; } } if ($this->_debug) { CrabTools::mydump($req['p'], REQ_DATA_ROOT . $mypre . '.param'); } if (isset(self::$exist_methods[$method])) { $caller =& self::$exist_methods[$method]; $c =& $caller[0]; $m = $caller[1]; } else { $caller = explode('.', $method); $cn = $caller[0]; $m = $caller[1]; $file = CONTROLLER_ROOT . "{$cn}.php"; if (!file_exists($file)) { throw new JsonServerExecption("method {$method} file not exist:(" . CONTROLLER_ROOT . "{$cn}.php)"); } @(require_once $file); $c = new $cn(); if (!method_exists($c, $m)) { throw new JsonServerExecption("{$cn} don't has callable method {$m}"); } } try { $ret = $c->{$m}($req['p']); //for debug if (isset(self::$record_users[$u])) { $dt = TT::get_tt('debug'); $dt->needSV = true; $dt->put(array('m' => $method, 'tm' => $_SERVER['REQUEST_TIME'], 'in' => $req['p'], 'out' => $ret)); } if (!$u) { $u = 'nouser'; } } catch (Exception $e) { $r['s'] = 'exc'; $r['msg'] = $e->getMessage(); $r['exce'] = $e->getTrace(); error_log($method . ':' . $r['msg']); } if ($this->_debug) { CrabTools::myprint($ret, REQ_DATA_ROOT . $mypre . '.resp'); } if (!$ret) { $ret['s'] = "KO"; $ret['msg'] = "{$cn}::{$m} return null"; } if ($log_nok) { if ($ret['s'] != 'OK') { TTLog::record(array('s' => 'OK', 'm' => $method, 'tm' => $tm, 'u' => $u, 'p' => $this->_raw_reg)); } } else { if (!array_key_exists($m, self::$nolog_methods)) { TTLog::record(array('s' => $ret['s'], 'm' => $method, 'tm' => $tm, 'u' => $u, 'p' => $this->_raw_reg)); } } return $ret; }