<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>

                在部署 Laravel 項目的時候,我們經常會使用到一個提升性能的命令: php artisan optimize 本文來看看這個命令執行背后的源碼: 首先我們可以使用編輯器搜 OptimizeCommand,應該就可以找到該命令源碼的所在: Illuminate\Foundation\Console\OptimizeCommand, 我們關注其中的 fire() 方法: ~~~ public function fire() { $this->info('Generating optimizedclass loader'); if ($this->option('psr')) { $this->composer->dumpAutoloads(); } else { $this->composer->dumpOptimized(); } $this->call('clear-compiled'); } ~~~ fire() 方法,默認情況下,會執行 `$this->composer->dumpOptimized()` 而這行代碼觸發 的其實就是 `composer dump-autoload --optimize` 源代碼可以在 Illuminate\Support\Composer 的 dumpOptimized() 找到: ~~~ public function dumpOptimized() { $this->dumpAutoloads('--optimize'); } ~~~ 最后,optimize 命令還執行了 `call('clear-compiled')` 其實就是觸發 `php artisanclear-compiled` 而很巧的是,我們也是可以直接使用編輯器搜ClearCompiledCommand 來 找到源碼,位于 `Illuminate\Foundation\Console\ClearCompiledCommand ` 中,這里的 fire() 方法其實關鍵的一步就是刪除了一下 cache 下的文件,我們來看: ~~~ public function fire() { $servicesPath = $this->laravel->getCachedServicesPath(); if (file_exists($servicesPath)) { @unlink($servicesPath); } $this->info('The compiled services file has beenremoved.'); } ~~~ 通過確定 $servicesPath 的位置,再使用 @unlink($servicesPath); 刪除。 確定 $servicesPath 的代碼 `$this->laravel->getCachedServicesPath() ` 位于 Illuminate\Foundation\Application 的 getCachedServicesPath 中: ~~~ public function getCachedServicesPath() { return $this->bootstrapPath().'/cache/services.php'; } ~~~ 這樣一看,其實就是將 bootstrap/cache/services.php 文件刪除,而這 個 services.php 是 Laravel 會自動生成的一個數組文件,這里指定了每個 Providers和 Facades 的位置和命名空間的全路徑等,在啟動 Laravel 項目的時候,可以直接讀取使 用。 所以這個命令可以拆為兩步: 1.`composer dump-autoload --optimize // composer 層面優化加載速度`2.`php artisan clear-compiled // 刪除 bootstrap/cache/services.php` 很清晰。
                  <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>

                              哎呀哎呀视频在线观看