問題描述
我剛剛繼承了一個帶有 PHP 腳本的站點,該腳本始終以 117 MB 的速度耗盡內存.即使我通過 php.ini 將 PHP 的 memory_limit 變量增加到 312 MB,也會發(fā)生這種情況.
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 的一個很好的線索,這個問題現(xiàn)在已經解決了.請參閱下面開始的答案:我終于找到了答案
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 的內存并運行 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 的頂部,我發(fā)現(xiàn)了以下聲明: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 放在那里的.根據(jù)以下網(wǎng)頁 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) 并重新運行腳本.它完成了數(shù)組合并并生成了 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') 工作,我現(xiàn)在為該特定腳本提供它需要的額外內存.我還將那臺服務器上的 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.
感謝大家?guī)椭鷻z測這個相當棘手的問題,尤其是 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.
這篇關于即使未達到 memory_limit,PHP 內存不足錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!