Composer Update failed — out of memory

后端 未结 25 2582
再見小時候
再見小時候 2020-12-01 00:40

I got this error when running composer.phar update on my VM:

PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried t

25条回答
  •  旧巷少年郎
    2020-12-01 01:09

    From my experience, memory errors from composer usually means it is spending too much memory looking for the right combinations of packages to install, especially the version constraints are not specific enough. For example, ^5.2.4 matches 5.3 to 5.3.29, 5.4 to 5.4.45, etc. For each specific version and permutation, composer has to get the package's dependencies to check if all the constraints are met. This is usually when the memory consumption gets huge.

    Once the versions have been figured out, the installation phase uses much less memory. The resolved versions for each package are also stored in a composer.lock file so that the specific permutation installed can be replicated in other environments. And this is the potential solution to your issue: run composer update in your dev machine (which should have enough memory), deploy the updated composer.lock, and run composer install on the server.

    Composer install will always reference the existing composer.lock for the versions to install for each package, and thus should seldom run into memory issues.

    For a reference on how to express version constraints in composer.json, check out https://getcomposer.org/doc/articles/versions.md

提交回复
热议问题