Slow updating of composer dependencies, despite --prefer-dist flag
When you run php composer.phar update and wait two minutes for what should be a routine dependency refresh, it usually means Composer is pulling source code from VCS repositories instead of downloading pre-packaged archives. The standard remedy found in many community threads is appending the --prefer-dist flag to force the use of dist packages. However, as seen in various reports, this flag alone often fails to resolve the issue if there are other factors preventing a direct download or forcing an update cycle that involves cloning repositories.
In the specific scenario where --prefer-dist appears ineffective, the root cause is frequently the presence of custom VCS repositories defined in your composer.json. When you declare a repository with "type": "vcs" and provide a URL pointing to a Git source, Composer treats this package as code that must be cloned from a remote server. Even if --prefer-dist is present, Composer cannot simply download a .zip file for a VCS repository because the archive does not exist in the public registry; it only exists within your specific Git branch or commit history.
Consider the configuration snippet below:
"repositories": [
{
"type": "vcs",
"url": "http://username:password@git.com/my-bundle.git"
}
]
Here, my-namespace/my-bundle is being resolved against a private Git repository. Because the package type is VCS, Composer must execute a git clone or git pull operation to fetch the source code and then run the installation scripts defined in that bundle. This process involves initializing a Git repository, checking out specific files, and running post-install commands. These steps are significantly slower than simply unzipping a pre-built .phar or tarball.
The --prefer-dist flag instructs Composer to prefer dist packages over source archives for standard package types (like Packagist entries). It does not override the behavior of VCS repositories, which inherently require source cloning. If your custom bundle is the only slow component, adding the flag will yield no improvement because the bottleneck lies in the Git operations required to satisfy the VCS dependency.
To resolve this without relying on --prefer-dist, you have two primary options depending on your workflow. First, if the custom bundle is available as a release on Packagist or another public registry, remove the VCS repository definition and point the requirement directly to the package name there. This allows Composer to download the dist archive instantly.
Second, if you must keep the bundle private but want faster updates, ensure that the Git repository contains pre-generated distribution packages within its branches (e.g., a dist branch), though this is less common for VCS types. A more pragmatic approach for frequent updates is to cache the Git clone operation or use a local mirror of your private repositories so Composer doesn't need to traverse the network or perform heavy Git operations every time you run an update.
It is also worth noting that if your custom bundle's composer.json specifies "type": "dist", Composer might still attempt to fetch it from VCS if the repository mapping forces a VCS resolution, creating a conflict between the package metadata and the repository type. Ensuring consistency between the repository type and the expected distribution method is key to avoiding these latency issues.