composer install is slow? How to speed up composer
composer install 为什么这么慢?怎么让composer加速?下面由composer使用教程栏目为大家讲解让composer加速的方法。
下面是一个composer install(在没有composer cache的情况下)做的所有事情:
[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 files
composer 在install的时候会做这几个事情:
去packagist.org中寻找对应需要的包的版本信息和下载地址
循环下载对应的包
解压安装对应的包
我们平时使用composer慢就可能在第一步和第二步出现慢。而第三步,由于php的版本或者依赖限制,也有可能安装失败。
第一步中的packagist.org保存了所有的第三方包的信息。要把这个信息文件从国外的网站拉取下来,这个本身就可能非常慢。
第二步获取了包信息之后,我们就需要把相关的包获取下来,这个时候如果包所在的地址(现在大多数包都放在github上了)访问非常慢,那么这一步就会非常慢了。
解决慢的办法有几个:
1 使用国内镜像。
(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 我们可以不可以自己搭建镜像呢?
可以的,这里有个开源项目(toran proxy)[https://toranproxy.com/]可以配合nginx很方便搭建属于自己的composer镜像。
自己的第三方包
还有一种需求,公司现在开发了一个第三方包,但是不希望开源到packagist.org上,只希望给自己公司内部使用。怎么办?
这个可以使用composer代理(satis)[https://github.com/composer/satis]来创建。搭建的方式也是非常简单的。其实上面说的toran proxy就是基于satis来创建的。
satis和toran的区别就是,satis只是做了代理,即将composer install的第一步做了替换,而toran则是将composer install的第一步和第二步都进行了替换。
结论
至此之后,再无composer install 慢的问题。
更多composer使用技术文章,请访问composer使用教程栏目!
The above is the detailed content of composer install is slow? How to speed up composer. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

When developing an e-commerce platform, it is crucial to choose the right framework and tools. Recently, when I was trying to build a feature-rich e-commerce website, I encountered a difficult problem: how to quickly build a scalable and fully functional e-commerce platform. I tried multiple solutions and ended up choosing Fecmall's advanced project template (fecmall/fbbcbase-app-advanced). By using Composer, this process becomes very simple and efficient. Composer can be learned through the following address: Learning address

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.

I had a tough problem when working on a project with a large number of Doctrine entities: Every time the entity is serialized and deserialized, the performance becomes very inefficient, resulting in a significant increase in system response time. I've tried multiple optimization methods, but it doesn't work well. Fortunately, by using sidus/doctrine-serializer-bundle, I successfully solved this problem, significantly improving the performance of the project.
