Home > Software engineering >  Can I specify php memory limit requirements in composer json? Perhaps in the "config.platform&q
Can I specify php memory limit requirements in composer json? Perhaps in the "config.platform&q

Time:05-01

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.

CodePudding user response:

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.

CodePudding user response:

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.

  • Related