<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 說明 前面所有分析,都是從`$response = $http->run();`展開的,經歷了漫漫長路,`run`方法終于運行完畢,返回一個`Response`對象,程序又回到入口文件: ``` . . . $response = $http->run(); $response->send(); $http->end($response); ``` 接下來是執行`$response->send();`。`send`方法: ``` public function send(): void { // 處理輸出數據 $data = $this->getContent(); // 如果還沒有發送響應頭且$this->header不為空 if (!headers_sent() && !empty($this->header)) { // 發送狀態碼 http_response_code($this->code); // 發送頭部信息 foreach ($this->header as $name => $val) { header($name . (!is_null($val) ? ':' . $val : '')); } } // 保存cookie $this->cookie->save(); // 輸出數據 $this->sendData($data); // 參考:http://www.laruence.com/2011/04/13/1991.html if (function_exists('fastcgi_finish_request')) { // 提高頁面響應 fastcgi_finish_request(); } } ``` 過程比較簡單:發送狀態碼、發送響應頭,然后發送響應內容。 # 收尾工作 接著是運行:`$http->end($response);`,展開如下: ``` public function end(Response $response): void { $this->app->event->trigger(HttpEnd::class, $response); //執行中間件 // 由此可以看出,可以在中間件添加end方法,在程序結束時執行 $this->app->middleware->end($response); // 寫入日志 $this->app->log->save(); } ``` 以上代碼執行完了之后,整個生命周期本該結束了,發現程序竟然還繼續執行`think\initializer\Error`類的`appShutdown`方法: ``` public function appShutdown(): void { if (!is_null($error = error_get_last()) && $this->isFatal($error['type'])) { // 將錯誤信息托管至think\ErrorException $exception = new ErrorException($error['type'], $error['message'], $error['file'], $error['line']); $this->appException($exception); } } ``` 開始是想可能是析構函數調用了它,但也沒有到有析構函數調用。最后發現,原來前面應用初始化的時候,加載了`think\initializer\Error`類,并執行了`init`方法: ``` public function init(App $app) { $this->app = $app; //開啟所有級別錯誤提示 error_reporting(E_ALL); //設置自定義的函數處理運行中的錯誤 set_error_handler([$this, 'appError']); //設置默認的異常處理程序,用于沒有用 try/catch 塊來捕獲的異常 set_exception_handler([$this, 'appException']); //注冊一個 callback ,它會在腳本執行完成或者 exit() 后被調用。 register_shutdown_function([$this, 'appShutdown']); } ``` 該方法最后一行注冊了一個回調,它會在腳本執行完成或者 exit() 后被調用。 # 生命周期小結 至此,一個精簡版的請求生命就結束了。一路下來,不停地單步執行、回放,像是代碼在大腦里一遍又一遍執行,還好堅持了下來。一個生命周期分析了一遍,還是有很大收獲的。后面計劃分析:事件機制、服務、Facade。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看