PHP Memory Allocation Limit Causes

狂风中的少年 提交于 2019-12-24 16:27:44

问题


I have 2 servers

Both server's have the same php memory_limit of 128M of data.

My Dev Server runs a script just fine, while on my prod server I am receiving a Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in ...

My question is what are other reasons I would be running out of memory in the prod environment even though my php memory_limits are the same?


回答1:


Preface

PHP is module that runs top of Apache [HTTPD Server] this involves linking the php interpreter against a library of hooks published by the webserver

Cause

Now it can exhaust due to scripts running allocating memory [RAM] & reach its threshold & get such errors.

Example big loops running & saving lots of data in memory which may over RUN the Memory

Possible Optimization you can do

memory_limit = 32M to your server's main php.ini file (recommended, if you have access)
php_value memory_limit 32M in your .htaccess file in the 

These are some work around for pages where you RUN out of Memory

ini_set('memory_limit', '-1'); overrides the default PHP memory limit (On individual php pages wherever you need extra memory)

Also some optimization you can do on HTTP Server (apache.conf or http.conf)

RLimitCPU,RLimitNPROC, RLimitMEM parameters can be adusted

Since you are running out of Memory you can adjust RLimitMEM

Syntax: RLimitMEM soft-bytes [hard-bytes]
Example: RLimitMEM 1048576 2097152

This directive sets the soft and hard limits for maximum memory usage of a process in bytes. It takes one or two parameters. The first parameter sets the soft resource limit for all processes. The second parameter sets the maximum resource limit. Either parameter can be a number, or ``max'', which indicates to the server that the limit should match the maximum allowed by the operating system configuration. Raising the maximum resource limit requires the server to be running as the user ``root'' or in the initial start-up phase.

You can put the lines in .htaccess files too [since in shared hosting you didnt have access to php.ini & http.conf files



来源:https://stackoverflow.com/questions/26636980/php-memory-allocation-limit-causes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!