views:

216

answers:

5

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /Library/WebServer/Documents/XMLDataStore.class.php on line 981

The curious thing about this error is not the memory leak, which would be easy enough to troubleshoot. Rather, it is the fact that XMLDataStore.class.php is only 850 lines long, which I have verified in multiple text editors.

This is with the PHP 5.3 bundled with Snow Leopard. I'm not using an opcode cache. Here is my php.ini:

allow_url_fopen = Off
error_reporting = -1
display_errors = 1
display_startup_errors = 1
date.timezone = 'America/Los_Angeles'
output_buffering = Off
realpath_cache_size = 0k

XMLDataStore.class.php has recently been refactored and it used to be longer than 981 lines. It's almost as if PHP has cached a 2-week-old version and is reading that. I'm positive that the current version at /Library/WebServer/Documents/XMLDataStore.class.php is only 850 lines long, though.

A: 

If you are getting an error on a non-existant line then it may very well be that PHP is caching it. Maybe try renaming it then executing it.

Not to sure about Snow Leopard, but I am using it right now and have to say there are a great deal of strange bugs with the OS alone, could be that.

I experienced this error before when I was accessing a DB and storing info in an array, turns out I forgot how large the DB was and when it passed MB on the stack I got that error and it stopped. If the situation is similar use a more processor heavy approach, such as connect, get a line/ block/ whatever, to something, then go back. Don't go through everything, store it all, then do something.

Check this out: Drupal.org memory allocation error

Hope this helps, not sure how clear all of this is. Maybe show parts of your script to get an idea of what might be causing this.

Tom
+2  A: 

Could this be a line break issue? i.e. the PHP interpreter breaking lines differently than your IDE / editor? I don't know about how PHP handles Linux/Mac/Windows linebreaks, but it might be a possibility. Can you create a fatal error somewhere in the script, and look which line number it shows you?

Could there be some over-long lines in your code (> 65535 characters) that mix up the line counting?

Also what happens if you rename the file, and include it under a new name? THis should take care of any screwed up cache issues.

Pekka
A: 

Here is some more info. I tried the same code on a different Mac running the same version of Snow Leopard - one that is rarely used for development and would not have a version of this file cached - same result.

Next I tried copying the same code to a Solaris box running PHP 5.2.8. I still get the memory error - which is fine and expected, of course, since it does exist - but the PHP error message says this instead:

Fatal error: Maximum function nesting level of '100' reached, aborting! in /export/www/htdocs/XMLDataStore.class.php on line 741

This makes perfect sense, as that is the first line of a method that is being called recursively by another method. Exact same code with same line breaks (LF) checked out at the same revision # from the same SVN repository on all 3 machines.

Bug in PHP 5.3.0 for Snow Leopard? :)

alexantd
A: 

While I have no idea what may cause this wrong line counting (I'm using PHP 5.3 on OSX 10.6, too. No Problems here.), you can narrow down the actual error by dividing your script into smaller parts. that way maybe you'll find the real location of your error.

And a 850 line PHP file could seriously use some refactoring anyway.

Techpriester
A: 

Php Seems to have issues with macintosh style line ending, It doesnt count the cr at the end of comments. I had this issue after opening a file on a friends apple. I used kate on linux and Crimson Editor on Windows to change the end of line back to Unix style and the line numbers worked fine.

hk135