我可以在作曲家JSON中指定PHP内存限制要求吗?也许在“ config.platform”中节点?
我刚刚有一个内存限制错误,然后在.ini文件中解决了它。不用担心。但是,我想将一些内容放在我的软件包作曲家中。我知道如何在Composer.json中指定PHP版本要求 - 我只是想知道是否可以由作曲家添加/检查其他平台要求。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作曲家可以检查软件以验证它们是否对应。但是,它不会检查系统(CPU,内存...)。您可以在readme.md文件中指定要求。
您可以在脚本中添加代码中所需的内存限制。但是,通常,默认的内存限制就足够了。您可能会通过添加Yeld或迭代器来优化循环。
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.
Composer.json中可用的属性的完整列表已有很好的记载。
在用户系统上提出要求的唯一一个是
需要
部分。这可以包括平台依赖项 ://getComposer.org/doc/01-basic-usage.md#platform-packages“ rel =“ nofollow noreferrer”>在“基本用法”页面上)以虚拟软件包的形式展示PHP,其扩展和相关库以及作曲家本身。这些是作为依赖项解决过程的一部分而不是应用程序运行时解决的,尽管您可以启用额外的平台检查。请注意,
config
部分配置了作曲家本身的行为,而不是软件包的行为,并且标记为“仅根” - 也就是说,当另一个项目使用您的库时,它甚至都不会读取。platform> platform> platform> platform> option
您提到的是平台需求的对面:它告诉作曲家即使在没有的情况下也要假装某些约束。
如果要在运行时验证特定的配置已经到位,而不仅仅是记录它,则可以使用诸如 ini_get 。这可以作为某些相关对象或函数的初始化的一部分运行,也可以作为 autoLoad 节中中,以便随着应用程序启动时始终执行。
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. Theplatform
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.更新:尽管这是提供的唯一工作解决方案 - 请阅读评论线程。有反对这个的好论点。此外,这需要关于写作和部署供应商软件包的强大工作知识。具体来说,当发布更好的解决方案或修复了问题的软件包时,您将需要知道如何回滚。
在您的作曲家项目或软件包中添加一个小PHP文件。
composer.json
tweak_ini.php
显然您需要添加一些逻辑以确保您不降级。
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
tweak_ini.php
Obviously you'll want to add some logic to make sure you aren't downgrading.