致命错误:X:wampwwwxxx 中的内存不足(已分配 1134559232)(试图分配 32768 字节)

2022-01-05 00:00:00 php mysql phpmyadmin wampserver

我在个人 PC 上的本地主机上使用 WAMP 服务器(32 位).我有一个大(非常大)多维数组,它通过读取包含长句子的 CSV 文件(CSV 文件包含 20,000 行信息)来获取其信息.问题是我在进行一些计算时收到以下错误:

I am using WAMP server(32 bits) on local host on my personal PC. I have a big (very big) multidimensional array which gets its information by reading a CSV file which contains long sentences(the CSV file contains 20,000 row of information). The problem is that I get the following error when it goes through some calculations:

致命错误:内存不足(已分配 1134559232)(尝试分配32768 字节)在 x:wampwwwxxx

我尝试了不同的解决方案,例如增加 upload_max_filesizepost_max_sizemax_file_uploadsmemory_limit 或将其设置为 -1在 php.ini 或我的脚本开头也没有人工作.请帮助我,请不要让我重新构建我的代码或更改 WAMP 的版本,由于某些原因这是不可能的.非常感谢你.:)

I tried different solutions like increasing upload_max_filesize, post_max_size , max_file_uploads and memory_limit or set it to -1 in php.ini or at the beginning of my scripts also, no one works. Please help me, and please do not ask me to re-architect my codes or change the version of WAMP, due to some reasons it is not possible. Thank you very much. :)

推荐答案

我终于找到了解决方案.我发现当PHP收集垃圾越来越满时,没有办法释放它.Unsetgc_collect_cycles() 也无效.唯一的方法是在不同的代码段上使用Function.就我而言,我在 for 循环中有一个大脚本,所以我将所有代码复制到一个函数中,并在我的循环中调用该函数.每次函数安静时,内存就会得到释放.您可以通过在函数中添加一次 memory_get_usage() 并在函数外添加一次来测试它以查看差异.

Finally I could find the solution. I found that when the PHP collection garbage is getting full, there is no way to free it. Unset and gc_collect_cycles() also are not effective. The only way is to use Function over different section of codes. In my case, I had a big script in a for loop, so I copied all my codes in a function, and in my loop I call the function. Each time function quiets, memory gets free. You may test it by adding memory_get_usage() once in your function and once out of the function to see the difference.

相关文章