【问题标题】:PHP Memory Allocation Limit CausesPHP内存分配限制原因
【发布时间】:2014-12-25 13:10:06
【问题描述】:

我有两台服务器

两个服务器的 php memory_limit 相同,都是 128M 的数据。

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

我的问题是,即使我的 php memory_limits 相同,我在 prod 环境中也会出现内存不足的其他原因是什么?

【问题讨论】:

  • 他们使用的是同一个版本的php吗?
  • ...几乎任何东西...通常这是输入/输出的问题,您要确保数据的输入和输出完全相同(例如:确保您的开发数据库是与此测试的生产数据库相同)。但是话又说回来:如果您的开发保持刚刚,而生产刚刚结束,任何模块的任何简单的次要版本更改都可能导致这种情况。
  • 这主要取决于您对数据的处理方式。如果有一个糟糕的例程,它可能会在几乎没有测试数据的开发服务器上运行。只需检查错误消息的代码行。
  • PHP 是模块化的,http 具有参数,这些参数与 RLimitCPU、RLimitNPROC、RLimitMEM 变量对内存进行了限制,可以根据您的需要进行优化

标签: php linux memory out-of-memory dev-to-production


【解决方案1】:

前言

PHP 是在 Apache [HTTPD 服务器] 之上运行的模块,这涉及将 php 解释器与网络服务器发布的挂钩库链接

原因

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 

这些是针对内存不足的页面的一些解决方法

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

您还可以在 HTTP 服务器上进行一些优化(apache.conf 或 http.conf)

RLimitCPU,RLimitNPROC, RLimitMEM parameters can be adusted

由于内存不足,您可以调整 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 文件

【讨论】:

    猜你喜欢
    • 2010-12-26
    • 2019-03-05
    • 2021-11-23
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多