Why is PHP Composer so slow?

Why is PHP Composer so slow?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why is PHP Composer so slow?

Running composer init followed by composer install on a project with zero dependencies should theoretically be an instant operation. It involves creating a manifest file and downloading a single PSR-4 autoloader. Yet, developers frequently report waits of several minutes for this minimal setup. The frustration is understandable: the task appears trivial, yet the tool behaves as if it is orchestrating a massive deployment.

The core reason for this latency lies in Composer's default security model regarding package repositories. When you run composer install, the installer does not simply download the files listed in your composer.json. It first validates every package against the configured repositories to ensure they are trusted and accessible. By default, Composer is configured to interact with Packagist.org.

Even if your composer.json contains no dependencies, the installation process must verify the integrity of the root package itself. In many environments, this verification step triggers a connection to the remote repository metadata API. If your network environment has strict outbound filtering, or if DNS resolution for the composer repository is slow due to upstream issues, the client hangs while attempting to resolve these dependencies before it can proceed to download the actual autoloader files.

Furthermore, Composer performs extensive validation on the composer.json file structure and the lock file generation process. It calculates hashes, checks for conflicts in the metadata, and ensures that the package registry response matches expectations. This background processing is necessary to maintain dependency integrity but adds significant overhead when the network latency is high. The "zero dependencies" scenario often exposes these hidden costs most clearly because there are no other tasks to distract from the initial repository handshake.

Configuring Repository Speed

To mitigate this behavior, you must explicitly adjust how Composer handles repository interactions. The primary lever is the repositories configuration in your composer.json. While Packagist is the standard for public packages, some internal workflows or specific hosting environments benefit from using a local mirror or a faster proxy.

You can configure a custom repository in your composer.json like this:

{
    "name": "your/project",
    "version": "1.0.0",
    "description": "",
    "require": {},
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/your-group/package"
        }
    ],
    "config": {
        "secure-http": false,
        "platform": {
            "php": "8.1"
        }
    }
}

However, replacing the default Packagist repository entirely is rarely necessary unless you are in a restricted network environment. A more practical approach involves adjusting Composer's download concurrency and cache settings via your global composer.json configuration file located at ~/.config/composer/config.json (on Linux/Mac) or %APPDATA%\Composer\config.json (on Windows).

You can increase the number of parallel downloads, which significantly reduces the time spent waiting for multiple assets:

{
    "config": {
        "http-timeout": 0,
        "process-timeout": 0,
        "disable-tls-auth": false,
        "vendor-dir": "vendor"
    }
}

The composer init Distinction

Regarding your specific question about why composer init does not handle the autoloader: composer init is strictly a scaffolding command. Its sole purpose is to generate the project skeleton, including the composer.json and composer.lock files based on your inputs. It intentionally avoids downloading any packages because doing so would contradict its design as a lightweight initialization tool.

The separation of concerns is deliberate. composer init prepares the ground; composer install executes the heavy lifting. This architecture allows developers to inspect the dependency graph before committing to a download, ensuring that no unexpected packages are pulled into the environment during the initial project spin-up.

If you require faster initialization for CI/CD pipelines or local development without dependencies, the solution is not to merge these commands but to optimize the network layer and cache settings mentioned above. Additionally, ensuring your system's php version matches the one expected by Composer can prevent unexpected retries caused by version mismatch errors in the lock file generation process.

Our network