Forum Moderators: coopster

Message Too Old, No Replies

Serious PHP memory management problem

seeking expertise in PHP memory management

         

meingallsphp

5:52 pm on Dec 26, 2005 (gmt 0)

10+ Year Member



I have a PHP page that reads emails from an email account, parses them, processes the resulting information, and then sends out a response. I am in the process of testing it right now, and I am using a small sample (11 emails). I expect, when the site is fully functional, that I could be processing hundreds of emails at a time. I am running the site on a managed server that is dedicated, so I have a fair amount of memory.

Unfortunately, I get a fatal error:

Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 6 bytes) in funcs_parse_emails.php on line 48

after only six emails. Clearly, if I am using up 42 megabytes, I have a serious problem.

Is there someone out there who can point me to a book or website that discusses PHP memory management issues or provides tools I can use? Alternatively, is there someone who has expertise in this area who would be willing to help me?

Thank you,

Mel

coopster

2:04 pm on Dec 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, meingallsphp.

Looks to me like you are continually loading up code in an include() or else you are populating more and more variables. One way or another you are loading up your memory allocation. Are you running a loop that continually includes() another file or something that may be quite large?

meingallsphp

7:44 pm on Dec 27, 2005 (gmt 0)

10+ Year Member



Thank you. I did find one small include file in a loop. I moved it outside the loop. This did not solve the problem, however.

Are you aware of any tools that can help me debug to see where the memory is being allocated?

If I reset a variable to an empty string, does that free the memory? Is there another way to free memory that I do not allocate explicitly?

Thanks.
Mel

mm1220

8:30 pm on Dec 27, 2005 (gmt 0)

10+ Year Member



How about posting some code? I haven't had dinner yet and some meaty php to get my teeth into could be just the ticket ... ;)

meingallsphp

10:35 pm on Dec 27, 2005 (gmt 0)

10+ Year Member



Thank you to those who were willing to help me here. It is terrific to have a support community!

I found the PHP function memory_get_usage, and by putting in a bunch of echo statements, I was able to determine where my problem was. (It turned out to be an "=" instead of an "==" in a conditional, which resulted in an endless loop. It's always something trivial, isn't it?)

For those of you facing memory usage problems, this function (memory_get_usage)is great.

Mel

coopster

12:59 am on Dec 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Good for you. I figured it was something inside a loop that caused your issue ... I may have run into this once myself you know ;)

meingallsphp

3:31 am on Dec 28, 2005 (gmt 0)

10+ Year Member



I found a PHP function - memory_get_usage - that tells me how much memory is being used at any given time. Using it, I was able to debug the program.

Thank you to all who helped me. I appreciate your assistance!

Mel