Asitis
Asitis

Reputation: 432

PHP Composer Autoloading takes forever

Whenever I run composer update the 'Generating autoload files' part always takes forever (sometimes up to 2 full minutes). I've ran it with the --profile flag to pinpoint this issue.

I've read multiple articles on it, but I still can't understand why it takes this long on my projects, and if it's even useful for my projects? I'm running into this whenever I'm deploying changes live, and I want that deployment to be as fast as possible. I've tried to run it with --no-dev flag, but that doesn't change anything.

So my question is, why would autoloading take so long (and how could I improve its speed)?

Upvotes: 12

Views: 14204

Answers (1)

Pierre
Pierre

Reputation: 1583

Depending on how your autoloader is configured in your composer.json file, composer can scan every single file in your project looking for classes. For big projects, this can take quite some time. Especially when using the classmap setting in composer. To speed up the autoload generation, you would want to use something like the PSR-4 autoloader, specifying a namespace prefix for your classes, but this might require some changes in your project depending on how your project and classes are structured.

Upvotes: 10

Related Questions