Exemple #1
0
 public function testLogger()
 {
     Logger::init(__DIR__, 'wisphp');
     for ($i = 0; $i < 4; $i++) {
         Logger::warn(str_repeat($i, 1024));
     }
     //        Logger::flush();
 }
Exemple #2
0
 /**
  * Execute filter
  *
  * @param $filtername
  *
  * @return bool
  */
 public function execute($filtername)
 {
     if (!isset($this->impFilters[$filtername])) {
         //Logger::debug('miss filter %s',$filtername);
         return true;
     }
     $this->app->timer->begin('f_' . $filtername);
     $filters = $this->impFilters[$filtername];
     foreach ($filters as $filter) {
         if ($filter->execute($this->app) === false) {
             Logger::debug('call filter %s.%s=false', $filtername, get_class($filter));
             $this->app->timer->end('f_' . $filtername);
             return false;
         }
         //Logger::debug('call filter %s.%s=true',$filtername, get_class($filter));
     }
     $this->app->timer->end('f_' . $filtername);
     return true;
 }
Exemple #3
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();
     }
 }
Exemple #4
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();
 }
Exemple #5
0
 /**
  * process
  */
 protected function process()
 {
     $className = $this->opts['c'];
     $cls = new $className();
     if (!method_exists($cls, 'execute')) {
         Color::error('方法execute不存在');
         $this->endStatus = self::ENDSTATUS_INIT;
         $this->help(1);
     }
     $rMethod = new \ReflectionMethod($cls, 'execute');
     $params = $rMethod->getParameters();
     $_opts = array();
     foreach ($params as $param) {
         $name = $param->getName();
         if (isset($args[$name])) {
             $_opts[] = $args[$name];
         } else {
             $_opts[] = null;
         }
     }
     try {
         call_user_func_array(array($cls, 'execute'), $_opts);
     } catch (Exception $ex) {
         Logger::fatal($ex->getMessage());
         $this->endStatus = self::ENDSTATUS_ERROR;
         exit(2);
     }
 }