Composer out of memory errors

When bundles are being built Servd will run composer install to make sure all of your project's packages are ready and waiting for you when you deploy the bundle.

Sometimes composer can experience an out of memory error during this process as the Servd Task Runner limits its maximum memory to 1.5GB.

There are two things you can do to ensure that this is no longer a problem.

Commit a composer.lock file

You should always commit a composer.lock file.

It not only vastly reduces the amount of memory needed to run composer install, it also ensures that the versions of packages installed in your bundle are an exact match against those you were using during local development.

Include yiisoft/yii2-redis in your composer.json

Servd requires a package called yiisoft/yii2-redis to be installed so that we're able to store your cache and session files in Redis. The task runner will check to see if you have already included it in your composer.json and composer.lock files. If it finds it, it doesn't need to do anything else and everyone can get on with their day.

If it doesn't find it, it runs composer require yiisoft/yii2-redis. This kicks off a process which checks all of the versions of yii2-redis against all of the versions for your other dependencies to try to find any conflicts. It is this process which often causes out of memory errors.

The solution is simple though: just composer require yiisoft/yii2-redis during local development which will add yii2-redis to your composer.json and composer.lock files. Once they're in there and comitted, Servd will no longer attempt to install the package and your memory errors should vanish!