composer install 爲何這麼慢?
下面是一個composer install(在沒有composer cache的狀況下)作的全部事情:php
[vagrant@localhost composer]$ ../composer_git/bin/composer install -vvv Reading ./composer.json Loading config file /home/vagrant/.composer/config.json Loading config file /home/vagrant/.composer/auth.json Loading config file ./composer.json Executing command (CWD): git describe --exact-match --tags Executing command (CWD): git branch --no-color --no-abbrev -v Executing command (CWD): hg branch Executing command (CWD): svn info --xml Failed to initialize global composer: Composer could not find the config file: /home/vagrant/.composer/composer.json To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section Loading composer repositories with package information Downloading http://packagist.org/packages.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/packages.json into cache Installing dependencies (including require-dev) Downloading http://packagist.org/p/provider-2013$8e290f3d47387c614761a9dc40a2ef6fb7dafb0cfe2264296e8fab2c6ee36bff.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-2013.json into cache Downloading http://packagist.org/p/provider-2014$c0d0e03ec56584b3bf3148ac1565d89e789a57b90d72f83a7a54a55fbfc4f083.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-2014.json into cache Downloading http://packagist.org/p/provider-2014-07$9b2d66a77e2f17ca1c18602419a2b53b00d42e0010d0a64fbbdcc1a01bbe092b.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-2014-07.json into cache Downloading http://packagist.org/p/provider-2014-10$ed15097a7afa5a3f48b27f0ce38c5e3e8943514a0bdfd1898af31c9f8f913edb.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-2014-10.json into cache Downloading http://packagist.org/p/provider-2015-01$3180dce46ea79fa77320185df239a62c07f6dbdeb21bc8ac6cd85b5d911a21ea.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-2015-01.json into cache Downloading http://packagist.org/p/provider-2015-04$7e98f73b92b237ae4f6b07c8b8bd2e754357c86214cddf53cfafe8554b30f8b4.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-2015-04.json into cache Downloading http://packagist.org/p/provider-archived$dfa1d92d2697fc375a1d522ab573634ee18807646f4abc322b6933157a07b829.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-archived.json into cache Downloading http://packagist.org/p/provider-latest$115a50bcbcb32507b9b7b41a1d44b80ddd4848fb12cefee5769e9eb71769f7a8.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/p-provider-latest.json into cache Downloading http://packagist.org/p/monolog/monolog$c1954eb1d33e701ea323b97ff003a6495c79b138fe68a9087a9dce1d06e90ebc.json Writing /home/vagrant/.composer/cache/repo/http---packagist.org/provider-monolog$monolog.json into cache - Installing monolog/monolog (1.0.0) Downloading https://api.github.com/repos/Seldaek/monolog/zipball/433b98d4218c181bae01865901aac045585e8a1a Downloading: 100% Writing /home/vagrant/.composer/cache/files/monolog/monolog/433b98d4218c181bae01865901aac045585e8a1a.zip into cache Extracting archive Executing command (CWD): unzip '/vagrant/composer/vendor/monolog/monolog/2db4c7a59b236e77c15ff6a4f279a2c6' -d '/vagrant/composer/vendor/composer/abaad4e5' && chmod -R u+w '/vagrant/composer/vendor/composer/abaad4e5' REASON: Required by root: Install command rule (install monolog/monolog 1.0.0) Writing lock file Generating autoload filescomposer 在install的時候會作這幾個事情:nginx
- 去packagist.org中尋找對應須要的包的版本信息和下載地址
- 循環下載對應的包
- 解壓安裝對應的包
咱們平時使用composer慢就可能在第一步和第二步出現慢。而第三步,因爲php的版本或者依賴限制,也有可能安裝失敗。
第一步中的packagist.org保存了全部的第三方包的信息。要把這個信息文件從國外的網站拉取下來,這個自己就可能很是慢。
第二步獲取了包信息以後,咱們就須要把相關的包獲取下來,這個時候若是包所在的地址(如今大多數包都放在github上了)訪問很是慢,那麼這一步就會很是慢了。git解決慢的辦法有幾個:
1 使用國內鏡像。github
- (http://pkg.phpcomposer.com/repo/packagist/)[http://pkg.phpcomposer.com]
- (http://comproxy.cn/repo/packagist)[https://phphub.org/topics/57]
- (https://toran.reimu.io/repo/packagist/)[https://toran.reimu.io/]
2 咱們能夠不能夠本身搭建鏡像呢?json
能夠的,這裏有個開源項目(toran proxy)[https://toranproxy.com/]能夠配合nginx很方便搭建屬於本身的composer鏡像。api
本身的第三方包
還有一種需求,公司如今開發了一個第三方包,可是不但願開源到packagist.org上,只但願給本身公司內部使用。怎麼辦?composer
這個可使用composer代理(satis)[https://github.com/composer/satis]來建立。搭建的方式也是很是簡單的。其實上面說的toran proxy就是基於satis來建立的。ide
satis和toran的區別就是,satis只是作了代理,即將composer install的第一步作了替換,而toran則是將composer install的第一步和第二步都進行了替換。svn
結論
至此以後,再無composer install 慢的問題。網站