Composer 2: What's New?

Composer, a dependency manager for PHP, was released about 8 years ago and today a new version is published, 2.0. Composer has received many new features over the years and has kept pace with PHP standards. The second version is compatible with older projects, but will bring some more great new features. In this article I will tell you more about them.

Acceleration and optimization

Performance improvements have been made in this release. Now it does not take into account already installed packages, as a result the update is much faster. We've also improved memory and processor handling.

. vendor , , . .

, , , , , hirak/prestissimo, .

Composer v2 is almost 2x faster when installing laravel / laravel without caching.
Composer v2 2 , laravel/laravel .

Composer . , Composer install/update .

, COMPOSER_DISABLE_NETWORK=1 :

COMPOSER_DISABLE_NETWORK=1 composer install

. , .:

https://repo.packagist.org could not be fully loaded (Network disabled, request canceled: https://repo.packagist.org/packages.json), package information was loaded from the local cache and may be out of date

, , :

The required git reference for gabrielanhaia/laravel-circuit-breaker is not in cache and network is disabled, aborting

--dry-run โ€œrequireโ€ โ€œremoveโ€

(composer update --dry-run. , , , vendor.

Composer 2.* composer require composer remove

root

root , .

, , :

Do not run Composer as root/super user! See https://getcomposer.org/root for details

Composer 2.* :

https://getcomposer.org/root for details
Continue as root/super user [yes]?

, . , --no-interaction

composer install --no-interaction

, . Composer 1.0 / . , ( ).

( ). , , packagist, .

, composer 2.x, . Composer 1.x , , , :

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://example.org",
            "canonical": false
        }
    ]
}

, , , , , .

, foo/bar some-vendor/ composer .:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://example.org",
            "only": ["foo/bar", "some-vendor/*"]
        }
    ]
}

toy/package , , , .

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://example.org",
            "exclude": ["toy/package"]
        }
    ]
}

only, exclude , (*), .\

If for some reason you want to ignore a specific platform requirement, you can simply run the command: composer install --ignore-platform-req php

It will skip the requirement for PHP or specific version. If you are going to ignore all the requirements, you should use the command already available in previous versions --ignore-platform-reqs

Other updates

There are many new minor features and bug fixes that have improved usability and quality. If you're interested in learning more about them, check out the Github Release Notes .




All Articles