Exemple #1
0
 /**
  * 单个调取
  * @param  [array] $rawData [类,方法,参数]
  * @return [type]
  */
 public function call($rawData)
 {
     //local调用执行开始时间
     Runtime::execStart();
     $this->rawData = $rawData;
     $service = trim($rawData['service']);
     $method = trim($rawData['method']);
     $request = $rawData['args'];
     if (empty($service) || empty($method)) {
         throw new \Exception('Service:method must exists!');
     }
     $response = $this->callByParams($service, $method, $request);
     //向监控系统中打数据
     Monitor::pushMsg($rawData, $response);
     if ((APP_ENV == 'dev' || APP_ENV == 'test') && \Phalcon\DI::getDefault()['request']->hasQuery('debug')) {
         if (is_array($response)) {
             $data = $response;
             $data['url'] = 'localhost';
             ApiLog::addLog(array($rawData), array('1' => $data));
         }
     }
     return $response;
 }
Exemple #2
0
 public static function addPageLog($start, $source = 'remote', $type = 'report', $event = null, $state = false, $url = '', $runTime = 0)
 {
     if (APP_ENV == 'product' || !isset($_GET['debug'])) {
         return true;
     }
     if ($start == true) {
         self::$logStart = microtime(true);
         return true;
     }
     $logData = ['source' => $source, 'type' => $type, 'time' => 0, 'data' => []];
     $data = ['url' => null, 'event' => null, 'runTime' => 0, 'realTime' => 0, 'state' => false];
     $realTime = (microtime(true) - self::$logStart) * 1000;
     //        var_dump($event);
     //如果event不是数组
     if (!is_array($event)) {
         $logData['time'] = $realTime;
         $data['url'] = $url;
         $data['event'] = $event;
         $data['runTime'] = $runTime ? $runTime : $realTime;
         $data['realTime'] = $realTime;
         $data['state'] = (string) $state;
         $logData['data'][] = $data;
     } else {
         $logData['time'] = $realTime;
         foreach ($event as $k => $e) {
             $data['url'] = isset($url[$k]) ? $url[$k] : '';
             $data['event'] = $e;
             $data['runTime'] = $runTime[$k] ? $runTime[$k] : $realTime;
             $data['realTime'] = $realTime;
             $data['state'] = isset($state[$k]) ? $state[$k] : 'false';
             $logData['data'][] = $data;
         }
     }
     \Xz\Lib\Core\ApiLog::addStatLog($logData);
 }
Exemple #3
0
 public function callMulti($data = array())
 {
     //remote调用执行开始时间
     Runtime::execStart();
     foreach ($data as $k => $v) {
         $url = isset($v['url']) ? $v['url'] : $this->apiUrl;
         $callback = isset($v['callback']) ? $v['callback'] : null;
         $errorCallback = isset($v['error_callback']) ? $v['error_callback'] : null;
         $parameters = array('service' => $v['service'], 'method' => $v['method'], 'args' => isset($v['args']) ? $v['args'] : array());
         $this->rawData[$k + 1] = $parameters;
         $opt = isset($v['opt']) && is_array($v['opt']) ? $v['opt'] : array(YAR_OPT_PACKAGER => $this->packager);
         \Yar_Concurrent_Client::call($url, 'callService', array($parameters), $callback, $errorCallback, $opt);
     }
     \Yar_Concurrent_Client::loop(array($this, 'callback'), array($this, 'errorCallback'));
     \Yar_Concurrent_Client::reset();
     $resultData = self::$result;
     self::$result = array();
     if ((APP_ENV == 'dev' || APP_ENV == 'test') && DI::getDefault()['request']->hasQuery('debug')) {
         ApiLog::addLog($data, $resultData);
     }
     return $resultData;
 }