skip to Main Content

I just got a memory limit error and I solved it in my .ini files. No worries. However, I’d like to put something in my package composer.json to indicated that some minimum memory is required. I know how to specify a php version requirement in composer.json – I’m just wondering if other platform requirements can be added/checked by composer.

3

Answers


  1. Chosen as BEST ANSWER

    UPDATE: Although this is the only working solution provided - please read the comment thread. There are good arguments against this. Also, this requires strong working knowledge of writing and deploying vendor packages. Specifically, you'll want to know how to roll this back when a better solution is posted or the problematic package is fixed.

    Add a little php file to your composer project or package.

    composer.json

    {
        ... 
        "autoload": {
            ...
            "files": ["tweak_ini.php"]
        }
    }
    

    tweak_ini.php

    Obviously you'll want to add some logic to make sure you aren't downgrading.

    ini_set('memory_limit','1000M');
    ...
    

  2. Composer can check for software to verify if they are corresponding. But, it doesn’t check the system (CPU, memory…). You can specify the requirements in a readme.md file.

    You can add in your code the memory limit needed in your script. But, in general, the default memory limit is enough. You may be have loops you can optimize by adding yeld or iterators.

    Login or Signup to reply.
  3. The complete list of properties available in composer.json is very well-documented.

    The only one which makes requirements on a user’s system is the require section. This can include platform dependencies (also discussed on the "basic usage" page) in the form of virtual packages exposing the version of PHP, its extensions and related libraries, and Composer itself. These are resolved as part of the dependency resolution process, and not when the application runs, although you can enable an additional platform check.

    Note that the config section configures the behaviour of Composer itself, not the package, and is marked "root-only" – that is, it will not even be read when another project uses your library. The platform option which you’ve mentioned is the opposite of a platform requirement: it tells Composer to pretend certain constraints are met even when they are not.

    If you want to verify at run-time that a particular configuration is in place, rather than merely documenting it, you can easily write your own using functions such as ini_get. This can either be run as part of initialisation of some relevant object or function, or listed as a file include in the autoload section so that it will always be executed as the application starts up.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search