標簽(空格分隔): composer
--prefer-dist 會從github 上下載.zip壓縮包,并緩存到本地。下次再安裝就會從本地加載,大大加速安裝速度。但她沒有保留 .git文件夾,沒有版本信息。適合基于這個package進行開發。
--prefer-source 會從github 上clone 源代碼,不會在本地緩存。但她保留了.git文件夾,從而可以實現版本控制。適合用于修改源代碼。
接下來我們進行驗證。
1 準備測試環境和數據
1.1 新建一個測試項目,并指定依賴包 twig
[ahcj@localhost test]$ mkdir composer-test
[ahcj@localhost test]$ cd composer-test/
[ahcj@localhost composer-test]$ composer init --require="twig/twig:1.*" -n --profile
[6.1MB/0.00s] Memory usage: 6.07MB (peak: 6.17MB), time: 0s
1.2 確定緩存目錄 cache-files-dir 為 /home/ahcj/.cache/composer/files
[ahcj@localhost ~]$ /usr/bin/composer config --list
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https?://packagist.org
[repositories.packagist.org.allow_ssl_downgrade] true
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [https, ssh]
[vendor-dir] vendor (/home/ahcj/vendor)
[bin-dir] {$vendor-dir}/bin (/home/ahcj/vendor/bin)
[cache-dir] /home/ahcj/.cache/composer
[data-dir] /home/ahcj/.local/share/composer
[cache-files-dir] {$cache-dir}/files (/home/ahcj/.cache/composer/files)
....省略....
1.3 查找是否有twig的緩存
[ahcj@localhost coposertest]$ ll /home/ahcj/.cache/composer/files/twig
ls: 無法訪問/home/ahcj/.cache/composer/files/twig: 沒有那個文件或目錄
2 測試 --prefer-source
2.1 使用 --prefer-source 安裝,用了 31.26s
[ahcj@localhost composer-test]$ composer install --profile --prefer-source
[6.1MB/0.00s] Loading composer repositories with package information
[6.4MB/6.08s] Updating dependencies (including require-dev)
[102.7MB/18.84s] Package operations: 1 install, 0 updates, 0 removals
[102.7MB/18.84s] - Installing twig/twig (v1.34.4): [102.8MB/20.76s] Cloning f878bab48e from cache
[101.3MB/31.26s] Writing lock file
[101.3MB/31.26s] Generating autoload files
[101.3MB/31.26s] Memory usage: 101.31MB (peak: 109.88MB), time: 31.26s
2.2 刪除 vendor 目錄,重新使用 --prefer-source 安裝,用了 33.64s,基本沒有差別
[ahcj@localhost composer-test]$ rm -rf vendor
[ahcj@localhost composer-test]$ composer install --profile --prefer-source
[6.2MB/0.01s] Loading composer repositories with package information
[6.3MB/0.01s] Installing dependencies (including require-dev) from lock file
[6.8MB/0.02s] Package operations: 1 install, 0 updates, 0 removals
[6.8MB/0.02s] - Installing twig/twig (v1.34.4): [6.9MB/12.90s] Cloning f878bab48e from cache
[6.8MB/33.64s] Generating autoload files
[6.8MB/33.64s] Memory usage: 6.82MB (peak: 6.98MB), time: 33.64s
2.3 查看發現沒有緩存,都是直接下載的麻。
[ahcj@localhost composer-test]$ ll /home/ahcj/.cache/composer/files/twig
ls: 無法訪問/home/ahcj/.cache/composer/files/twig: 沒有那個文件或目錄
2.4 發現了版本控制信息
[ahcj@localhost composer-test]$ find -name .git
./vendor/twig/twig/.git
[ahcj@localhost composer-test]$ cd ./vendor/twig/twig/
[ahcj@localhost twig]$ git log | less
....好多,通通省略....
3 使用 --prefer-dist 安裝
3.1 使用 --prefer-dist 安裝,用了 20.34s
[ahcj@localhost composer-test]$ rm -rf vendor
[ahcj@localhost composer-test]$ composer install --profile --prefer-dist
[6.2MB/0.00s] Loading composer repositories with package information
[6.3MB/0.01s] Installing dependencies (including require-dev) from lock file
[6.8MB/0.01s] Package operations: 1 install, 0 updates, 0 removals
[6.8MB/0.01s] - Installing twig/twig (v1.34.4): [7.0MB/0.01s] D[7.0MB/12.99s] Downloading (0%)[7.0MB/12.99s] [7.0MB/14.48s] Downloading (5%[7.0MB/15.35s] Downloading (10[7.1MB/16.00s] Downloading (15[7.1MB/16.44s] Downloading (20%)[7.[7.1MB/16.86s] Downloading (25[7.1MB/17.08s] Downloading (30[7.2MB/17.50s] Downloading (35[7.2MB/17.71s] Downloading (40%)[7.[7.2MB/17.73s] Downloading (45[7.3MB/17.95s] Downloading (50[7.3MB/18.14s] Downloading (55[7.3MB/18.17s] Downloading (60%)[7.[7.3MB/18.36s] Downloading (65[7.4MB/18.38s] Downloading (70[7.4MB/18.57s] Downloading (75[7.4MB/18.59s] Downloading (80%)[7.[7.5MB/18.61s] Downloading (85[7.5MB/18.80s] Downloading (90[7.5MB/18.82s] Downloading (95[7.5MB/18.86s] Downloading (100%)[7.0MB/18.86s]
[6.8MB/20.34s] Generating autoload files
[6.8MB/20.34s] Memory usage: 6.84MB (peak: 8.12MB), time: 20.34s
3.2 找到了緩存
[ahcj@localhost composer-test]$ ll /home/ahcj/.cache/composer/files/twig
ls: 無法訪問/home/ahcj/.cache/composer/files/twig: 沒有那個文件或目錄
[ahcj@localhost composer-test]$ ll /home/ahcj/.cache/composer/files/twig
總用量 0
drwxrwxr-x 2 ahcj ahcj 58 8月 18 12:16 twig
3.3 重新使用 --prefer-dist 安裝,這次用了 6.43s,只有上次安裝的 1/4 時間
[ahcj@localhost composer-test]$ rm -rf vendor
[ahcj@localhost composer-test]$ composer install --profile --prefer-dist
[6.3MB/0.01s] Loading composer repositories with package information
[6.4MB/0.01s] Installing dependencies (including require-dev) from lock file
[6.9MB/0.01s] Package operations: 1 install, 0 updates, 0 removals
[6.9MB/0.02s] - Installing twig/twig (v1.34.4): [7.0MB/0.02s] Loading from cache[7.0MB/0.02s]
[6.9MB/6.43s] Generating autoload files
[6.9MB/6.43s] Memory usage: 6.87MB (peak: 7.13MB), time: 6.43s
3.4 并沒有 .git 版本控制信息喲
[ahcj@localhost composer-test]$ find -name .git