Home >Development Tools >composer >Solution to slow Composer update

Solution to slow Composer update

藏色散人
藏色散人forward
2019-08-08 17:54:234063browse

What should I do if Composer updates slowly? Below, the composer usage tutorial column will introduce you to the solution to the slow update of Composer. I hope it will be helpful to friends in need!

Solution to slow Composer update

Problem

Generally when we use composer install and composer update, sometimes the installation and update speed is very slow, slow It makes people anxious. At this time, we can solve this problem through the following solutions.

Cause of the problem

First of all, we need to know why it is slow? This is because generally, the data of the installation package (mainly zip files) is downloaded from github.com, and the metadata of the installation package is downloaded from packagist.org.

However, due to well-known reasons, the connection speed of foreign websites is very slow, and may be "walled" or even "non-existent" at any time.

What "Packagist China Full Mirror" does is to cache all installation packages and metadata to domestic computer rooms and accelerate them through domestic CDNs, so that there is no need to make requests to foreign websites, thereby accelerating composer The process of install and composer update is faster and more stable. Therefore, even if packagist.org and github.com fail (mainly because the connection speed is too slow or blocked), we can still download and update the installation package.

Solution

Now that we know the cause of the problem, we need to enable the local mirror service. There are two ways to enable this mirror service:

System global configuration: Add the configuration information to Composer’s global configuration file config.json;

Individual project configuration: Add the configuration information to a certain In the composer.json file of each project.

For system global configuration, open the command line window (windows users) or console (Linux, Mac users) and execute the following command:

composer config -g repo.packagist composer https://packagist.phpcomposer.com

For single project configuration, open the command line window ( Windows users) or console (Linux, Mac users), enter the root directory of the project (that is, the directory where the composer.json file is located), and execute the following command:

composer config repo.packagist composer https://packagist.phpcomposer.com

The above command will create the composer in the current project The mirror configuration information is automatically added at the end of the .json file (we can also add it manually):

"repositories": {
    "packagist": {
        "type": "composer",
        "url": "https://packagist.phpcomposer.com"
    }
}

Summary

In the normal development process, we will always encounter When we encounter this or that problem, we need to summarize and record our problems, the causes of the problems we analyzed, and the final solutions for later reference. I've always done this, and it helps me a lot.

The above is the detailed content of Solution to slow Composer update. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jellythink.com. If there is any infringement, please contact admin@php.cn delete