English 中文(简体)
Zend PHP 记录 memory_limit
原标题:Zend php memory memory_limit

全部

我正在开发一款基于Zend框架的Web应用程序。我们在开发服务器上不断遇到内存不足的错误:

可允许的内存大小已耗尽(尝试了YYYY字节...)

我们不断提高记忆——在php.ini,但现在已超过1000兆克。 什么是正常记忆——有限价值? 营地/Zend有哪些通常的嫌疑人可以脱掉记忆? 我们正在使用Propel ORM。

感谢一切帮助!

Update I cannot reproduce this error in my windows environment. If I set memory_limit low (say 16M), I get the same error, but the "tried to allocate" amount is always something reasonable. For example: (tried to allocate 13344 bytes) If I set the memory very low on the (Fedora 9) server (such as 16M), I get the same thing. consistent, reasonable out of memory errors. However, even when the memory limit is set very high on our server (128M, for example), maybe once a week, I will get an crazy huge memory error: (tried to allocate 1846026201 bytes). I don t know if that might shed any more light onto what is going on. We are using propel 1.5. It sounds like the actual release is going to come out later this month, but it doesn t look like anyone else is having this problem with it anyway. I don t know that Propel is the problem. We are using Zend Server with php 5.2 on the Linux box, and 5.3 locally.

还有其他的想法吗?我已经提交了一张票来安装Linux服务器上的Xdebug。

谢谢 (xiè xiè)

- 休养

最佳回答

I think this has something to do with deployment from cruise control. I only get the very high (on the order of gigs) memory error when someone is deploying new code (or just after new code has been deployed). This makes a little bit of sense too since the error always points to a line that is a "require_once." Each time I get an error: Fatal error: Out of memory (allocated 4456448) (tried to allocate 3949907977 bytes) in /directory/file.php on line 2

I have replaced the "require_once" line with: class_exists( Ingrain_Security_Auth ) || require( Ingrain/Security/Auth.php );

到目前为止,我已经替换了3个文件中的那一行,并且没有出现任何内存问题。有人能够说明一下可能发生了什么吗?我正在使用Cruise Control进行部署。

问题回答

一般来说,对于 PHP 5.2 和/或 PHP 5.3,我倾向于认为 memory_limit 大于 32M 是“太多了”:

  • Using Frameworks / ORM and stuff like this, 16M is often not enough
  • Using 32M is generally enough for the kind of web-applications I m working on (typical websites)
  • Using more than 64M means the server will not be able to handle as many users as we d like.


When, it comes to a script reaching memory_limit, the usual problem is trying to load too much data into memory ; a couple of examples :

  • Loading a big file in memory, with functions such as file or file_get_contents, or XML-related functions/classes
  • Creating a too big array of data
  • Creating too many objects

考虑到您使用了ORM,您可能会处于以下情况下:

  • You are doing some SQL query that returns a lot of rows
  • Your ORM is converting each row in objects, putting those in an array
  • In which case a solution would be to load less data
    • using pagination, for instance
    • or trying to load data as arrays instead of objects (I don t know if this is possible with Propel -- but it is with Doctrine ; so maybe Propel has some way of doing that too ? )

您的应用程序在耗尽内存时到底在做什么?可能有很多原因造成这种情况。我可以说最常见的原因就是将太多的数据分配给一个数组。您的应用程序有没有这方面的情况呢?

你有两件事情中的一件发生了,也许两件都发生了:

  1. You have a runaway process somewhere that isn t ending when it should be.
  2. You have algorithms that throw lots of data around, such as huge strings or arrays or objects, and are making needless copies instead of processing just what they need and discarding what they don t.




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签