Composer内存在共享主机上耗尽

时间:2016-09-02 22:52:50

标签: php symfony composer-php

共享FreeBSD主机上以前正在运行的沙箱现在无法运行composer update或安装内存耗尽错误。在昨天之前,我能够毫无问题地运行php ./composer.phar update。我不相信需要更多的内存。我可以在没有任何问题的情况下在Windows系统上更新项目。内存大小以外的哪些变量会导致内存耗尽错误?

为了测试这个,我将... / vendor和composer.lock文件的内容移动到另一个目录,然后运行php ./composer.phar install --prefer-dist。 [Composer位于项目目录中,因此我可以在本地更新它,而不是希望主机主机更新它。]上面的命令导致:

% php ./composer.phar install --prefer-dist
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 134217728 bytes) in phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 134217728 bytes) in phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

Composer是版本1.20

composer.json使用:

{
    "name": "truckee/projectmana",
    "license": "MIT",
    "type": "project",
    "description": "Project MANA administrative application",
    "autoload": {
        "psr-0": {
            "": "src/"
        }
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "jquery/jquery",
                "version": "1.11.1",
                "dist": {
                    "url": "https://code.jquery.com/jquery-1.11.1.js",
                    "type": "file"
                }
            }
        }
    ],
    "require": {
        "braincrafted/bootstrap-bundle": "~2.0",
        "doctrine/doctrine-bundle": "~1.4",
        "doctrine/doctrine-fixtures-bundle": "^2.3",
        "doctrine/orm": "^2.4.8",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "incenteev/composer-parameter-handler": "~2.0",
        "javiereguiluz/easyadmin-bundle": "~1.1",
        "jms/security-extra-bundle": "~1.5",
        "jquery/jquery": "1.11.*",
        "knplabs/knp-menu-bundle": "~2.0",
        "nelmio/alice": "^2.1",
        "oyejorge/less.php": "~1.5",
        "paragonie/random_compat": "^2.0",
        "php": ">=5.3.9",
        "psliwa/pdf-bundle": "dev-master",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "symfony/assetic-bundle": "dev-master",
        "symfony/monolog-bundle": "~2.4",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/symfony": "2.8.*",
        "twbs/bootstrap": "3.0.*",
        "twig/extensions": "1.0.*"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Braincrafted\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::install"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Braincrafted\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::install"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "stable",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "htdocs",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.3-dev"
        },
        "repositories": [
            {
                "type": "composer",
                "url": "http://packages.zendframework.com/"
            },
            {
                "type": "composer",
                "url": "http://packagist.org/"
            }
        ]
    },
    "require-dev": {
        "liip/functional-test-bundle": "^1.4",
        "symfony/phpunit-bridge": "^3.0"
    }
}

编辑: 可用内存:

% php -r "echo(ini_get('memory_limit'));"
128M

请求free -m: %free -m free:找不到命令。

-vv --profile

% composer update -vv --profile
[9.9MB/0.01s] Loading composer repositories with package information
[10.5MB/0.80s] Updating dependencies (including require-dev)
PHP Fatal error: ...

编辑#2,致命错误(使用作曲家1.1.0)继续,因为它与上面不同:

Allowed memory size of 1073741824 bytes exhausted (tried to allocate 32 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 32 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

3 个答案:

答案 0 :(得分:9)

你可以试试这个,我成功了

php -d memory_limit=-1 /usr/local/bin/composer/composer.phar require guzzlehttp/guzzle

这是我的第一个答案!!!哇

enter image description here

答案 1 :(得分:5)

虽然我以前曾尝试过这个,但我用php -d memory_limit=-1 ./composer.phar update取得了成功。

FWIW,这是% php -d memory_limit=-1 ./composer.phar -vv --profile update

的输出
[9.7MB/0.01s] Loading composer repositories with package information
[10.3MB/0.72s] Updating dependencies (including require-dev)
[1094.4MB/57.65s] Dependency resolution completed in 8.075 seconds
[1094.4MB/57.72s] Analyzed 8525 packages to resolve dependencies
[1094.4MB/57.72s] Analyzed 514764 rules to resolve dependencies
[1095.7MB/57.76s] Dependency resolution completed in 0.002 seconds
[287.5MB/66.04s] Generating autoload files
[288.1MB/67.86s] > post-update-cmd: Incenteev\ParameterHandler\ScriptHandler::buildParameters
[288.3MB/71.19s] Updating the "app/config/parameters.yml" file
[288.6MB/71.92s] > post-update-cmd: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
[288.7MB/86.31s] > post-update-cmd: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
[288.7MB/101.92s]
[288.7MB/101.92s]  // Clearing the cache for the dev environment with debug true
[288.7MB/101.92s]
[288.7MB/102.05s]                                                               
 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.    
[288.7MB/102.05s]                                                               

[288.7MB/102.12s] > post-update-cmd: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
[288.7MB/104.14s]
[288.7MB/104.14s]  Installing assets as hard copies.

[288.7MB/104.31s]  --- -------------------------- ----------------
[288.7MB/104.31s]       Bundle                     Method / Error
[288.7MB/104.31s]  --- -------------------------- ----------------
[288.7MB/104.31s]   ✔   FrameworkBundle            copy
[288.7MB/104.31s]   ✔   EasyAdminBundle            copy
[288.7MB/104.31s]   ✔   SensioDistributionBundle   copy
 --- -------------------------- ----------------
[288.7MB/104.31s]
[288.7MB/104.31s]  ! [NOTE] Some assets were installed via copy. If you make changes to these assets you have to run this command again.

[288.7MB/104.31s]                                                               
 [OK] All assets were successfully installed.                                   

[288.7MB/104.31s]
[288.7MB/104.38s] > post-update-cmd: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
[288.9MB/104.43s] Deprecation Notice: The callback Braincrafted\Bundle\BootstrapBundle\Composer\ScriptHandler::install declared at /home/projectmana/www3.projectmana.org/vendor/braincrafted/bootstrap-bundle/Braincrafted/Bundle/BootstrapBundle/Composer/ScriptHandler.php accepts a Composer\Script\CommandEvent but post-update-cmd events use a Composer\Script\Event instance. Please adjust your type hint accordingly, see https://getcomposer.org/doc/articles/scripts.md#event-classes in phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:289
[288.9MB/104.43s] Stack trace:
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:247
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:209
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:95
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/Installer.php:297
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/Command/UpdateCommand.php:174
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/vendor/symfony/console/Command/Command.php:259
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/vendor/symfony/console/Application.php:844
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/vendor/symfony/console/Application.php:192
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/Console/Application.php:231
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/vendor/symfony/console/Application.php:123
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/src/Composer/Console/Application.php:104
[288.9MB/104.43s]  phar:///home/projectmana/www3.projectmana.org/composer.phar/bin/composer:43
[288.9MB/104.43s]  /home/projectmana/www3.projectmana.org/composer.phar:24
[288.9MB/104.44s] > post-update-cmd: Braincrafted\Bundle\BootstrapBundle\Composer\ScriptHandler::install
Copied icon fonts to /home/projectmana/www3.projectmana.org/app/../web/fonts.
[288.9MB/105.09s] Memory usage: 288.87MB (peak: 1095.93MB), time: 105.09s

答案 2 :(得分:4)

Composer update使用大量内存来解决依赖性

只有少量内存的服务器上的唯一选择是通过将其提交到存储库或从持续集成服务器复制到服务器来提供composer.lock

没有其他方法可以在128mb ram的服务器上运行composer