Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is PHP Composer so slow?

Why is PHP Composer so slow when all I do is init a project with zero dependencies? Here are the commands I run:

composer init 

<step through composer.json creation, define 0 zero dependencies>

composer install 

Wait 3 minutes (not an exaggeration).

All composer has to do is pull in an autoloader and create /vendor, so why does it take so long? For that matter, why doesn't that step happen on composer init?

Is there a configuration option I can use to pull in a cached autloader and vendor upon init?

like image 991
AgmLauncher Avatar asked Feb 10 '15 16:02

AgmLauncher


People also ask

Why is composer so slow?

Composer update is very slow if you have a lot of dependencies/packages implemented. You should avoid variable versions and think about using a HHVM as server.

How can I make my composer faster?

Always composer update on your dev machine first, test it and if all test are valid deploy the composer. lock to your production environment and run composer install there. Now composer installes exactly the versions you tested before, even if there are newer (but untested) ones.

How can I speed up my composer update?

Go nuclear. Clear your cache, remove the vendor directory and lockfile, and do a composer update.


1 Answers

Because Composer is implemented by file_get_contents(). That has no TCP optimizations, no Keep-Alive, no multiplexing, etc.

I created a Composer plugin to download packages in parallel: https://packagist.org/packages/hirak/prestissimo

$ composer global require hirak/prestissimo

Please try it. In my environment, composer install becomes 10 times faster.

like image 154
hiraku Avatar answered Oct 03 '22 21:10

hiraku