Пример #1
0
 /**
  * Initial
  */
 protected function init()
 {
     // init web request
     $this->appId = $this->genAppId();
     $this->initAppEnv();
     $this->initConf();
     if ($this->debug !== true && isset($this->opts['D']) || isset($this->opts['debug'])) {
         $this->debug = true;
     }
     $this->initEnv();
     $this->initLog();
     if (true !== Conf::get('wisphp.disable_db')) {
         //没有强制关闭
         $this->initDB();
     }
 }
Пример #2
0
 /**
  * Record request data
  *
  * @param Application $app
  * @param  string     $requestfile
  */
 private function logRequest(Application $app, string $requestfile)
 {
     $headers = array();
     foreach ($app->request->serverEnvs as $key => $value) {
         if (strncmp('HTTP_', $key, 5) === 0) {
             $headers[$key] = $value;
         }
     }
     $file = $app->getDir('log') . $requestfile;
     $data = $app->request->inputs;
     $keyarr = Conf::get('wisphp.log.requestfilter', array());
     foreach ($keyarr as $key) {
         if (isset($data[$key])) {
             $data[$key] = '[removed]';
         }
     }
     $out = array('info' => $app->appId . ':' . $app->request->url . ':' . date('Y-m-d H:i:s', $app->request->now), 'cookie' => $app->request->cookies, 'header' => $headers, 'data' => $data);
     $dump = print_r($out, true);
     file_put_contents($file, $dump, FILE_APPEND);
 }
Пример #3
0
 /**
  * Send output
  */
 public function send()
 {
     $this->setFrHeader();
     $data = $this->formatResponse();
     $this->sendHeaders();
     // fetch the output data
     $ob = ini_get('output_buffering');
     if ($ob && strtolower($ob) !== 'off') {
         $str = ob_get_clean();
         //trim data
         $data = trim($str) . $data;
     }
     if ($data) {
         $outhandler = Conf::get('wisphp.outputhandler', array());
         if ($outhandler && !is_array($outhandler)) {
             // support string
             $outhandler = array($outhandler);
         }
         if ($outhandler) {
             // call the global output handlers
             foreach ($outhandler as $handler) {
                 if (is_callable($handler)) {
                     $data = call_user_func($handler, $data);
                 } else {
                     Logger::warn("outouthandler:%s can't call", is_array($handler) ? $handler[1] : $handler);
                 }
             }
         }
         echo $data;
     }
     $this->runTasks();
 }
Пример #4
0
 /**
  * Shutdown handler
  */
 public function shutdownHandler()
 {
     $result = $this->timer->getResult();
     $str[] = '[time:';
     foreach ($result as $key => $time) {
         $str[] = ' ' . $key . '=' . $time;
     }
     $str[] = ']';
     Logger::notice(implode('', $str) . ' status=' . $this->endStatus);
     Logger::flush();
     if (true !== Conf::get('wisphp.disable_db')) {
         //做一些清理
         \wisphp\db\TxScope::rollbackAll();
         \wisphp\db\Db::close();
     }
 }
Пример #5
0
 /**
  * Exception handler
  *
  * @param \Exception $ex
  */
 public function exceptionHandler($ex)
 {
     parent::exceptionHandler($ex);
     if (true === $this->debug) {
         echo "<pre>";
         print_r($ex->__toString());
         echo "</pre>";
     }
     $errcode = $ex->getMessage();
     if ($ex instanceof Exception && ($pos = strpos($errcode, ' '))) {
         $errcode = substr($errcode, 0, $pos);
     }
     if ($this->request->method == 'GET') {
         $retrycode = Conf::get('wisphp.error.retrycode', '/\\.net_/');
         $retrynum = $this->request->get('_retry', 0);
         $retrymax = Conf::get('wisphp.error.retrymax', 1);
         if ($retrycode && $retrynum < $retrymax && preg_match($retrycode, $errcode) > 0) {
             $retrynum++;
             $gets = array_merge($_GET, array('_retry' => $retrynum));
             $url = $this->request->url . '?' . http_build_query($gets);
             $this->response->setHeader('X-Rewrite-URI: ' . $url);
             $this->response->send();
             exit;
         }
     }
     $this->response->setFrHeader($errcode);
     $this->setHeader($errcode);
     if ($this->request->needErrorPage()) {
         $this->goErrorPage($errcode);
         exit;
     }
     $this->response->setException($ex);
     $this->response->send();
     exit;
 }
Пример #6
0
 public function __construct()
 {
     $this->methodExt = Conf::get('wisphp.methodExt', '');
 }