gpt4 book ai didi

php memory_limit 问题

转载 作者:行者123 更新时间:2023-12-01 00:32:46 25 4
gpt4 key购买 nike

我的一个脚本需要大内存。可能正因为如此,我遇到了以下错误

Fatal error: Out of memory (allocated 42729472) (tried to allocate 32 bytes)

我尝试使用 ini_set('memory_limit', '256M'); 更改 memory_limit在我的页面顶部,但我仍然遇到同样的问题。我也试过 ini_set('memory_limit', '512M');但没有运气。

最佳答案

您有权访问 php.ini 文件吗?然后在那里更改 memory_limit 值。

您还应该分析您的脚本。大量的数据库事务?他们中的许多人在循环?很多循环?很多临时变量? unset 的巧妙用法可以产生巨大的变化。

也很高兴知道:Performance ConsiderationsGarbage Collection

编辑(对为什么 memory_limit 不能与 ini_set 一起工作的问题的可能答案)

memory_limit integer This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

Prior to PHP 5.2.1, in order to use this directive it had to be enabled at compile time by using --enable-memory-limit in the configure line. This compile-time flag was also required to define the functions memory_get_usage() and memory_get_peak_usage() prior to 5.2.1.

When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

来源:php.net

关于php memory_limit 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3749464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com