mSubPath = $subPath; } protected $mExFiles; protected function setExFiles(array $files) { $this->mExFiles = $files; } protected function is_exclude($file) { $path = BASE_ROOT_PATH . "/" . $this->mSubPath . "/"; $file = str_replace($path,'',$file); return in_array($file,$this->mExFiles); } private function clear_global() { $_SESSION = []; $_COOKIE = []; $_POST = []; $_GET = []; } public function handle_error($level, $message, $file, $line) { if($level == E_NOTICE) return; $trace = "handle_error: level={$level},msg={$message} file={$file},line={$line}\n"; $backtrace = debug_backtrace(); foreach ($backtrace as $item) { $trace .= "{$item['file']}\t{$item['line']}\t{$item['function']}\n"; } Log::record($trace,Log::ERR); } protected function preLooper() { set_error_handler([$this, 'handle_error']); } abstract function handle_req($file); public function run_looper() { Log::record(__FUNCTION__,Log::DEBUG); $this->preLooper(); Log::record('Waiting......',Log::DEBUG); $i = 0; fcgi_init(); while(($ret = fcgi_accept()) >= 0) { $mem = memory_get_usage(); Log::record("index = {$i} memory={$mem} ",Log::DEBUG); ++$i; $start = microtime(true); ob_start(); $this->clear_global(); perfor_clear(); perfor_start(); Log::start_sql_log(); init_request(); init_cookie($_SERVER['HTTP_COOKIE']); http_header::instance()->start(); $file = request_helper::script_file(); $this->handle_req($file); fcgi_headers_sent(); $contents = ob_get_clean(); fcgi_echo($contents); Log::end_sql_log(); $perlog = perfor_log(); $mem = memory_get_usage(); Log::record("memory={$mem} perlog = {$perlog}" ,Log::DEBUG); $ret = fcgi_fini(); $mem = memory_get_usage(); $msg = sprintf("memory={$mem} isCgi = {$ret} request time=%.6f\r\n\r\n",microtime(true) - $start); Log::record($msg ,Log::DEBUG); } fcgi_fini(); Log::record('Waiting quit......',Log::DEBUG); } }