Esempio n. 1
0
 public function log($level, $message, array $context = [])
 {
     if (empty($context)) {
         Tracks::instance()->track('es:query', $message);
     } else {
         Tracks::instance()->track('es:response', $context);
     }
 }
Esempio n. 2
0
 private function _exec($options, $returnInfo = false)
 {
     $ch = curl_init();
     if ($this->debug === true) {
         $options[CURLOPT_VERBOSE] = true;
     }
     if (!isset($options[CURLOPT_RETURNTRANSFER])) {
         $options[CURLOPT_RETURNTRANSFER] = true;
     }
     if (!isset($options[CURLOPT_HTTPHEADER])) {
         $options[CURLOPT_HTTPHEADER] = ['Expect: '];
     } else {
         $options[CURLOPT_HTTPHEADER] = array_merge($options[CURLOPT_HTTPHEADER], ['Expect: ']);
     }
     curl_setopt_array($ch, $options);
     $result = curl_exec($ch);
     $this->lastRequestContentResult = $result;
     $this->lastRequestInfoResult = curl_getinfo($ch);
     if ($returnInfo) {
         $result = $this->lastRequestInfoResult;
     }
     curl_close($ch);
     Tracks::instance()->track('hadoop:curl', ['request' => $options, 'response' => $result]);
     return $result;
 }
Esempio n. 3
0
 /**
  * 解析请求并挂载到指定应用
  * 
  * @param  Request $request
  * 
  * @return \Ws\Mvc\App
  */
 private static function parseMointpoints(Request $request)
 {
     static $firstIs = true;
     $pathinfo = $request->pathinfo();
     \Ws\Debug\Tracks::instance()->track('sys:init', $pathinfo);
     $mounts = (array) self::$config->get('app.mounts');
     if ($firstIs) {
         // 格式化 $mounts
         foreach ($mounts as $appId => $options) {
             if (is_dir($options['dir'])) {
                 $options['dir'] = rtrim($options['dir'], '\\/');
                 $options['mount'] = rtrim($options['mount'], '\\/') . '/';
                 $options['len'] = strlen($options['mount']);
                 $mounts[$appId] = $options;
             } else {
                 unset($mounts[$appId]);
             }
         }
         $mounts = Arrays::sort_by_col($mounts, 'len', SORT_DESC);
         self::$config->set('app.mounts', $mounts);
         $firstIs = false;
     }
     $app = null;
     // 定位挂载点
     foreach ($mounts as $appId => $options) {
         $pa = $pathinfo;
         $idstr = '/^' . str_replace('/', '\\/', $options['mount']) . '/i';
         // 匹配pathinfo /a => /a/ 的区别
         if ($options['mount'] == "{$pa}/") {
             $pa = "{$pa}/";
         }
         if (preg_match($idstr, $pa)) {
             $app = self::loadApp($appId, $options);
             if (!empty($app)) {
                 $pathing = preg_replace($idstr, '', $pa);
                 $app->setPathing($pathing);
             }
             break;
         }
     }
     return $app;
 }