RepDetec
RepDetec

Reputation: 751

Zend php memory memory_limit

All,

I am working on a Zend Framework based web application. We keep encountering out of memory errors on our dev server:

Allowed memory size of XXXX bytes exhausted (tried YYYY...

We keep increasing memory_limit in php.ini, but it is now up over 1000 megs. What is a normal memory_limit value? What are the usual suspects in php/Zend for running out of memory? We are using the Propel ORM.

Thanks for all of the help!

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.

Any more ideas? I have a ticket out to get Xdebug installed on the Linux box.

Thanks,

-rep

Upvotes: 1

Views: 6014

Answers (4)

RepDetec
RepDetec

Reputation: 751

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');

I have replaced that line in 3 files so far, and have not had any more memory issues. Can anyone shed some light into what might be going on? I am using Cruise Control to deploy.

Upvotes: 0

Pascal MARTIN
Pascal MARTIN

Reputation: 401002

Generally speaking, with PHP 5.2 and/or PHP 5.3, I tend to consider than more than 32M for memory_limit is "too much" :

  • 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

Considering you are using an ORM, you might be in a situation where :

  • 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 ? )

Upvotes: 5

staticsan
staticsan

Reputation: 30555

You have one of two things happening, perhaps both:

  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.

Upvotes: 0

KTastrophy
KTastrophy

Reputation: 1739

What exactly is your application doing at the time it runs out of memory. There can be a lot of causes for this. I'd say most common would be allocating too much data to an array. Is your application doing anything along those lines.

Upvotes: 0

Related Questions