0

I am running a php script as a process on a Linux shell. With different tools (top, xdebug, ...) I see the dynamic memory consumption (heap memory) of this very complex script continuously rising.

How can I find out exactly the line in the code or the variable or the place, that is causing this behavior? Where is the memory leak of the php script?

Additional information:

  • Linux version 2.6.30-gentoo-r4
  • PHP Version 5.2.10-pl0-gentoo
  • I can modify the script
  • I can use xdebug

Please give a reason for closing this question.

7
  • This is usually done via profiling. xdebug.org/docs/profiler Commented Jan 9, 2014 at 17:20
  • I tried running thre file with xdebug. All I got was a 60000 line long list of system calls and the corresponding memory consumption. This did not answer the question, where exactly the memory leak is. Commented Jan 9, 2014 at 17:22
  • 1
    php 5.2 doesn't have a garbage collector. Every time memory is allocated it's basically leaked, since it will never be reclaimed. 5.3 added a garbage collector. Commented Jan 9, 2014 at 17:24
  • Does it mean my question cannot be answered without looking by hand at all of these 60000 lines (and more)? Commented Jan 9, 2014 at 17:25
  • 1
    The nature of debugging in most languages is that it is very tedious, unfortunately. If all you have to go is "my program uses a lot of memory", that's not necessarily a leak, it could just be poor structure. So most likely you do need to look at what is going on in tedious detail and decide where your most serious problems form. Finally, true leaks (due to lost references) in a language like php should be very unusual, except in cases where what jordanm said is true (no GC), in which case you are wasting your time trying to stop them. Commented Jan 9, 2014 at 17:58

1 Answer 1

1

Try this at suspect areas

echo memory_get_usage();

// Suspect code here

echo memory_get_usage();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.