我可以在作曲家JSON中指定PHP内存限制要求吗?也许在“ config.platform”中节点?

发布于 2025-01-25 14:20:21 字数 120 浏览 2 评论 0 原文

我刚刚有一个内存限制错误,然后在.ini文件中解决了它。不用担心。但是,我想将一些内容放在我的软件包作曲家中。我知道如何在Composer.json中指定PHP版本要求 - 我只是想知道是否可以由作曲家添加/检查其他平台要求。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桃扇骨 2025-02-01 14:20:22

作曲家可以检查软件以验证它们是否对应。但是,它不会检查系统(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.

痴意少年 2025-02-01 14:20:22

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. 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.

鲜肉鲜肉永远不皱 2025-02-01 14:20:22

更新:尽管这是提供的唯一工作解决方案 - 请阅读评论线程。有反对这个的好论点。此外,这需要关于写作和部署供应商软件包的强大工作知识。具体来说,当发布更好的解决方案或修复了问题的软件包时,您将需要知道如何回滚。

在您的作曲家项目或软件包中添加一个小PHP文件。

composer.json

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

tweak_ini.php

显然您需要添加一些逻辑以确保您不降级。

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

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');
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文