PHP内存分配限制原因 [英] PHP Memory Allocation Limit Causes

查看:101
本文介绍了PHP内存分配限制原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2台服务器

两个服务器的php memory_limit都具有相同的128M数据.

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

我的开发服务器运行的脚本很好,而在生产服务器上,我收到一个致命错误:...允许的内存大小为134217728字节,已用尽(尝试分配32字节)...

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 ...

我的问题是,即使我的php memory_limits相同,我仍会在产品环境中耗尽内存的其他原因是什么?

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?

推荐答案

前言

PHP是在Apache [HTTPD Server]之上运行的模块,它涉及将php解释器链接到由Web服务器发布的钩子库中

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

原因

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

您可以进行的可能的优化

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)

还可以在HTTP Server(apache.conf或http.conf)上进行一些优化

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

RLimitCPU,RLimitNPROC, RLimitMEM parameters can be adusted

由于内存不足,您可以调整RLimitMEM

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.

您也可以将这些行放在.htaccess文件中[由于在共享托管中您无权访问php.ini& http.conf文件

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

这篇关于PHP内存分配限制原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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