Register now and start sharing your code snippets.
-->

How to debug memory allocation problems in PHP with Xdebug

PHP posted 3 months ago by christian

Xdebug is a good tool for finding the root cause of memory allocation problems such as the one shown here:

   1  Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes)

First install Xdebug by following the Xdebug installation instructions.

Next surround the code you suspect is causing the problem with the following function calls:

   1  xdebug_start_trace('/tmp/mytrace');
   2  ...
   3  Bad bad PHP code
   4  ...
   5  xdebug_stop_trace();

Read this blog entry by splitbrain.org for more details

Tagged xdebug, php, memory, error, performance