PHP内存不足错误,即使未达到memory_limit [英] PHP out of memory error even though memory_limit not reached

查看:109
本文介绍了PHP内存不足错误,即使未达到memory_limit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用PHP脚本继承了一个站点,该站点始终以117 MB的内存耗尽.即使当我通过php.ini将PHP的memory_limit变量增加到312 MB时,也会发生这种情况.

I have just inherited a site with a PHP script that is consistently running out of memory at 117 MB. This happens even when I increase PHP's memory_limit variable to 312 MB, which I'm doing via php.ini.

由于pcguru提供了很好的线索,现在可以解决此问题.请参阅下面的答案:我终于找到了答案

This is now solved thanks to a great clue from pcguru. See my answer below that begins: I have finally found the answer

ini_get('memory_limit')返回php.ini中设置的值,因此我确定Apache在更改该值后已重新启动.我正在使用memory_get_usage(true)来返回脚本在执行过程中各个点所消耗的内存.当达到117 MB时,它始终会失败.

ini_get('memory_limit') returns the value set in php.ini, so I'm certain Apache has restarted after changing the value. I'm using memory_get_usage(true) to return the memory consumed by the script at various points along the way. And it's consistently failing when it gets to 117 MB.

我是否没有意识到内部PHP的限制,即它从未为单个脚本分配超过117MB的内存?

Is there some internal PHP limit I'm unaware of that has it never allocate more than 117MB to an individual script?

该服务器具有1GB的RAM,并且正在运行CentOS.我具有root shell访问权限. PHP是5.3.18版. MySQL是5.1.66-cll版本.

The server has 1GB of RAM and is running CentOS. I have root shell access. PHP is version 5.3.18. MySQL is version 5.1.66-cll.

此脚本位于用户名/密码的后面,我无法向其提供公共访问权限.

This script is behind a username/password and I can't provide public access to it.

编辑后添加:

1)谢谢大家迄今为止的帮助.您可以在以下针对各种答案的针对特定用户评论的回复中找到更多信息.

1) Thanks all for your help to date. You'll find more info in my replies to specific user comments under various answers below.

2)绝对未安装Suhosin.我已经检查了多个地方,包括运行脚本,检查常量和运行php -v

2) Suhosin is definitely not installed. I've checked in multiple places including running a script and check for constants and running php -v

3)apache日志中没有我收到的特定错误消息的记录.在php.ini中打开了日志记录.我通过grep通过管道搜索了整个日志.

3) The apache log has no record of the specific error message I'm getting. Logging is switched on in php.ini. I piped through grep to search the entire log.

4)在这种情况下是否有可能报告了错误的错误?

4) Is it possible the wrong error is being reported in this case?

推荐答案

我终于找到了答案.线索来自pcguru的回答,开头是由于服务器只有1 GB的RAM ...".

I have finally found the answer. The clue came from pcguru's answer beginning 'Since the server has only 1 GB of RAM...'.

我直觉上想看看Apache是​​否有自己的内存限制,因为这些限制可能会影响PHP分配内存的能力.在httpd.conf的顶部,我发现了以下语句:RLimitMEM 204535125

On a hunch I looked to see whether Apache had memory limits of its own as those were likely to affect PHP's ability to allocate memory. Right at the top of httpd.conf I found this statement: RLimitMEM 204535125

这是由whm/cpanel放在的.根据以下网页,whm/cpanel错误地在虚拟服务器上计算其值... http://forums.jaguarpc.com/vps-dedicated /17341-apache-memory-limit-rlimitmem.html

This is put there by whm/cpanel. According to the following webpage whm/cpanel incorrectly calculates its value on a virtual server... http://forums.jaguarpc.com/vps-dedicated/17341-apache-memory-limit-rlimitmem.html

大部分时间都用完了脚本,因此我将RLimitMEM增加到268435456(256 MB),然后重新运行该脚本.它完成了阵列合并,并生成了供下载的csv文件.

The script that runs out of memory gets most of the way through, so I increased RLimitMEM to 268435456 (256 MB) and reran the script. It completed its array merge and produced the csv file for download.

ETA:在进一步了解RLimitMEM和RLimitCPU之后,我决定将它们从httpd.conf中删除.这允许ini_set('memory_limit','### M')起作用,现在我为该特定脚本提供所需的额外内存.我还将该服务器上的RAM加倍.

ETA: After further reading about RLimitMEM and RLimitCPU I decided to remove them from httpd.conf. This allows ini_set('memory_limit','###M') to work, and I now give that particular script the extra memory it needs. I also doubled the RAM on that server.

感谢大家在发现这个棘手的问题上所给予的帮助,尤其是pcguru,他想出了使我找到解决方案的重要线索.

Thank you to everyone for your help in detecting this rather thorny issue, and especially to pcguru who came up with the vital clue that got me to the solution.

这篇关于PHP内存不足错误,即使未达到memory_limit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆