title: How do you debug php "Out of Memory" issues?
body: <p>I've had some issues lately with PHP memory limits lately:</p>
  
  <blockquote>
    <p>Out of memory (allocated 22544384) (tried to allocate 232 bytes)     </p>
  </blockquote>
  
  <p>These are quite the nuisance to debug since I'm not left with a lot of info about what caused the issue.</p>
  
  <p>Adding a shutdown function has helped</p>
  
  <pre><code>register_shutdown_function('shutdown');
  </code></pre>
  
  <p>then, using <a href="http://php.net/manual/en/function.error-get-last.php" rel="noreferrer">error_get_last</a>(); I can obtain information about the last error, in this case, the "Out of memory" fatal error, such as the line number, and the php file name.  </p>
  
  <p>This is nice and all, but my php program is heavily object oriented.  An error deep in the stack doesn't tell me much about the control structure or the execution stack at the moment of the error.  I've tried <a href="http://php.net/manual/en/function.debug-backtrace.php" rel="noreferrer">debug_backtrace(),</a> but that just shows me the stack during shutdown, not the stack at the time of the error.</p>
  
  <p>I know I can just raise the memory limit using ini_set or modifying php.ini, but that doesn't get me any closer to actually figuring out what is consuming so much memory or what my execution flow looks like during the error.</p>
  
  <p>Anyone have a good methodology for debugging memory errors in advanced Object Oriented PHP programs?</p>