CakePHP 2.2.3 - 调试“在0行上未知时耗尽的内存”错误

I have a CakePHP 2.2.3 applicaiton that's running perfectly fine on our Dev server, a Debian Squeeze LAMP box from Turnkey Linux. We're using InMotion hosting for our production server, and moving our code over to this server has been DISASTEROUS.

While testing out AJAX functionality on one page, we were getting the terribly unhelpful:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 389245600 bytes) in Unknown on line 0

tl;dr: I am looking for suggestions on how we can debug this issue

My first course of action was to strip down all the code within the controller functions to the bare minimum. The index() action of one of my controllers contains ONE line of code, and still somehow manages to exceed 256mb of memory per execution:

$this->autoRender = false;

To take the above point to the extreme, I commented out EVERY line of the Model & Controller that is generating this error. Still running out of memory. Several other pages that make MySQL database requests also display this "memory exhausted" error despite the fact that they load completely. Other pages, the memory error is more of a show-stopper and completely prevents execution.

I have tried raising the memory limit from 256 to 512 or even 1024mb, all this does is suppress the error message itself. The page does not route/render or do anything, it just silently fails.

At the suggestion of another SO post, I tried turning Debug from 2 down to 0, which does not help the issue at all either.

We do not have XDebug installed on our production server, so I am at a loss as to how I'm supposed to track down the issue for our web host to fix the problem.

The VPS we are using is a CentOS 5.8 server running Apache 2.2.23, MySQL 5.3.18, and CakePHP 2.2.3

Our webhost can't or won't provide any further information on the subject. They suggested we "ask the Cake devs if they've seen anything like this before", which I feel is a very cowardly way to kick the can down the road. I'm hoping that someone here on SO has seen something like this issue before and might be able to help.

I've seen this problem before, and it may be because you're not using Containable behavior. It's happened to me many times before I learn to set $recursive = -1 on AppModel (or any model you're using). Unless you're managing tons of info per page knowingly, you should restrict the data retrived. It's important to maintain the retrieval of models to the minimum, using a combination of the Containable Behaviour and $recursive

Just a tip: it can be a session problem. If you store too much in $_SESSION, session_start() can do such a thing for it has to read all the shit you've stored. Just try this:

$_SESSION = array();

If this helps, you'll find out the rest.