2

PHP is intermittently reporting ridiculous allocation errors.

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

It tried to allocate more than 4GB of memory. What? Where is Unknown line 0? Where did it try to allocate?

I am not explicitly allocating any memory in my PHP code and I am not using anything other than stock PHP calls. I see that the last line of raw HTML in my PHP file (after i exit the php block) is emitted and in the loaded page, so the problem doesn't appear to be occurring in my actual PHP code. Code it be something that I am doing that is triggering this?

I have found that this seems to happen more frequently if I try to reload a PHP file in the browser shortly after having edited the actual PHP file, but I don't know if this is a good data point or not.

PHP version is 5.3.26.

Why am I getting these errors, and is this something I need to worry about for production?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Michael
  • 9,060
  • 14
  • 61
  • 123
  • This kind of error is often symptomatic of a rogue database query, large image handling processes etc – scrowler Dec 09 '14 at 18:41
  • 1
    It may be worth upgrading your PHP, if that's an option. 5.3.26 isn't even the latest version of 5.3, and we're up to 5.6 now. It's at least *possible* that there's better error information available for this problem in later releases. I can [at least one bug complaining about this lack of error information that's been closed since the release you're running](https://bugs.php.net/bug.php?id=65455)... – Matt Gibson Dec 09 '14 at 18:54
  • @MattGibson Thanks Matt, I've got a 5.5.14 install that I'll try when I get a chance here. – Michael Dec 09 '14 at 20:57

1 Answers1

2

The most common reasons for an exhausted memory pool are either you've either done something resource intensive (i.e. tried to open a 20GB text file and load it into memory) or you've done something that gets into an infinite loop (or runs enough times to exhaust the memory pool, i.e. a SQL query that returns a large number of rows).

Where is Unknown line 0? Where did it try to allocate?

PHP can't tell you that because it happened on the execution (i.e. op code) layer. PHP manages your pool for you (in fact, it's pretty hard to get it to where you can manage it directly because it obfuscates it by design).

Look for a loop in your code. Even a small one can potentially produce this error, even if it appears benign.

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • There is one loop, a `foreach` that iterates all the files in a given directory, and determines whether or not to create a link or image for that file. – Michael Dec 09 '14 at 20:55