March 13th, 2000, 04:11 PM
I've been using PHP for a few weeks and was going along quite nicely until I started to stress my application a little more than before and had the following error half-way through a page display:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 12288 bytes) in calcprofile.inc on line 144
I'm not particularly bothered about the code line in question (in fact it's just a debug message) but I'm interested in understanding what is happening with the PHP memory management. While my code is pretty intensive in terms of number of calculations per page request, I can't believe I'm using over 8M of memory per page request - doesn't PHP automatically clean up variable memory after each page request?
The alternative is that I really am using that much memory (eeek), in which case is there anyway I can improve the memory management myself? I use mysql_free_result() as soon as I finish with a request but nothing else explicit. Maybe functions should be used rather than includes() whenever possible? This is all a nasty surprise for a C++ programmer who is used to cleaning up nicely behind themselves :-)
Any feedback or ideas would be really appreciated...thanks.
Oh, I'm running PHP3 under Apache on Linux.
March 13th, 2000, 04:48 PM
Yes, php cleans up after itself, so it is your script that is using that much memory. If you're freeing your SQL results there isn't much else I can say without looking at your code (and I don't think I want to do that!). You can increase the available memory by changing the memory_limit directive in the php3.ini file.
March 15th, 2000, 04:56 PM
In the end I moved some code that was simply "include()"d and made it into a function - this seems to have dramatically reduced the memory usage and my problems have gone!
So the moral of the story is write your code properly in the first place and don't nest includes!