#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    2
    Rep Power
    0
    Hi Everyone

    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.


    -Mark.
    zigzagzoo.com
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.

    good luck
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    2
    Rep Power
    0
    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!


    -Mark.
    zigzagzoo.com

Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 11:45 PM
  2. How to see the Memory used by a PHP script?
    By Pardall in forum PHP Development
    Replies: 4
    Last Post: February 13th, 2004, 04:54 PM
  3. Replies: 4
    Last Post: January 28th, 2004, 09:29 AM
  4. php for checking mail errors
    By jnccneto in forum PHP Development
    Replies: 0
    Last Post: January 25th, 2004, 09:15 PM
  5. Q: PHP memory footprint in include() & RW
    By Clan admin in forum PHP Development
    Replies: 0
    Last Post: January 25th, 2004, 05:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo