Jump to content

Allowed memory size of 134217728 bytes exhausted


Recommended Posts

Posted

Hey!

 

I'm using OOP PHP and when including the class_lib.php file in two of my other files, I encountered this error:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 30720 bytes) in /home1/cbeppe/public_html/database.php on line 17

 

What I find weird about this (apart from the 30KB memory limit) is that it's a very contradictory message. 30720 (30KB) is significantly less than 134217728 (128MB), and so there shouldn't really be a problem...

 

Additional info that might help:

 

Username: Cbeppe

URL: ntdrunk.heliohost.org

Server: Stevie

Size of included PHP file: 5KB

Size of all files involved: ca. 15KB

 

I found a way to do it without including my class library twice so it's not urgent. Just thought you should know ;)

 

Thanks in advance for any help! :)

 

 

 

Posted

That's weird considering I have drupal installed (consisting of hundreds of source files, and thousands of lines of code), and it doesn't have any problems.

Posted
(...)

What I find weird about this (apart from the 30KB memory limit) is that it's a very contradictory message. 30720 (30KB) is significantly less than 134217728 (128MB), and so there shouldn't really be a problem...

(...)

 

Just to clear your confusion:

 

The error mean that the system failed to allocate another 30 kB of memory after (let's say) 127.99 MB being already allocated before processing line 17 of your script.

 

If you are coding by yourself you might want to use memory_get_usage(true); function to debug how much memory is allocated for your script. You could put it in various parts of your code to check memory consumption of these parts of your code. Then you can think about what you can code in different way to optimise memory consumption.

 

 

 

--------

 

I had a problem not so long time ago with one of my custom scripts (the biggest, most server resources consumming one) after moving between hosts. While on first webhost I had no problems, on the second one the script went into exhausting allowed limit of 128MB of memory. What was the difference between two webhosts? One is using 32bit system, second one has 64bit system. I don't know if this is the case for all 32/64bit systems, but on the one I used the same processes takes almost twice (not twice, but little less than twice) amount of memory on 64bit system than 32bit.

 

So I had to optimise my script. The amount of data that my script used when being stored in files was just ~2 MB, however when being loaded, exploded into arrays and processed accordingly it takes MUCH more. I have changed procedure to load into arrays only the part of data that is currently needed, not all data at once. Unset unused variables/arrays also helped a little bit. The size of the PHP script itself doesn't mean much; what and how the script is doing - does.

Posted

Thanks for clearing that up, Piotr.

 

The file in question that caused the problem was an included (as in the include() function) class library. I'm not completely sure how PHP handles included data, but apparently it takes up significantly more memory than it does disk space.

 

I'll look into reducing the memory consumption of my scripts.

 

 

Cbeppe.

Guest
This topic is now closed to further replies.
×
×
  • Create New...