Composer version 2 is now available, this a good update for PHP developers as the new the version comes with a lot of performance improvements over the previous version.
Composer 2.0 Changelog
- Many CPU and memory performance improvements
- The update command is now much more deterministic as it does not take the already installed packages into account
- Package installation now performs all network operations first before doing any changes on disk, to reduce the chances of ending up with a partially updated vendor dir
- Partial updates and require/remove are now much faster as they only load the metadata required for the updated packages
- Added a platform-check step when vendor/autoload.php gets initialized which checks the current PHP version/extensions match what is expected and fails hard otherwise. Can be disabled with the platform-check config option
- Added a
Composer\InstalledVersionsclass which is autoloaded in every project and lets you check which packages/versions are present at runtime
- Added a
composer-runtime-apivirtual package which you can require (as e.g.
^2.0) to ensure things like the InstalledVersions class above are present. It will effectively force people to use Composer 2.x to install your project
- Added support for parallel downloads of package metadata and zip files, this requires that the curl extension is present and we thus strongly recommend enabling curl
- Added parallel installation of packages (requires OSX/Linux/WSL, and that
unzipis present in PATH)
- Added much clearer dependency resolution error reporting for common error cases
- Added support for updating to a specific version with partial updates, as well as a –with flag to pass in temporary constraint overrides
- Added automatic removal of packages which are not required anymore whenever an update is done, this will purge packages previously left over by partial updates and
- dded support for TTY mode on Linux/OSX/WSL so that script handlers now run in interactive mode
canonicaloptions to all repositories, see repository priorities for details
- Added support for many new lib-* packages in the platform repository and improved version detection for some ext-* and lib-* packages
pre-operations-execevent to be fired before the packages get installed/upgraded/removed
pre-pool-createevent to be fired before the package pool for the dependency solver is created, which lets you modify the list of packages going in
post-file-downloadevent to be fired after package dist files are downloaded, which lets you do additional checks on the files
- Added –locked flag to
showcommand to see the packages from the composer.lock file
- Added –unused flag to
removecommand to make sure any packages which are not needed anymore get removed
- Added –dry-run flag to
- Added –no-install flag to
removecommands to disable the install step and only do the update step (composer.lock file update)
Refer to this link to list the complete composer 2.0 changelog.
How to upgrade?
- Composer 2.0 still supports PHP 5.3 and above, much like Composer 1.x
composer.lockfiles are interoperable between versions, so you can upgrade to 2.0 and roll back easily if needed.
- Most commands and arguments remain the same, and largely what you know about Composer remains true in 2.0.
If you run
composer self-update from 1.x, it will warn you that a new stable major version of Composer is available, and you can use
composer self-update --2 to migrate to it.
Should you encounter issues, you can go back at any time by using
composer self-update --1. Hopefully that will make everyone feel comfortable to experiment with the new release.
If you are installing Composer automatically from the installer script, and wish to remain on Composer 1.x for the time being, you can also pass it a
--1 argument to prevent it from installing Composer 2.0 by default. If you do this please remember and aim to upgrade in a timely manner, as Composer 1.x will not be maintained for very long.
Command "self-update" is not defined. ? If you installed Composer via your OS package manager, the self-update command may not be available. Use
which composer to find its path (e.g.
/usr/bin/composer), then run the install script adding
--install-dir /usr/bin --filename composer (adjusting the install dir to match your path) to the
php composer-setup.php line.