[xdebug-general] Re: stacktrace on memory exhausted

From: Jack Bates <ms419[@]freezone.co.uk>
Date: Wed, 26 Nov 2008 09:21:51 -0800

On Wed, 2008-11-26 at 09:33 +0100, Derick Rethans wrote:
> On Tue, 25 Nov 2008, Jack Bates wrote:
> > I am not yet using a remote debugger with Xdebug, but the stacktraces
> > Xdebug prints are already a boost to my productivity - thanks!
> >
> > Today I am trying to get my app to run with 16M of memory or less, so I
> > keep seeing:
> >
> > Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to
> > allocate 4864 bytes)
> > in /home/jablko/public_html/qubit/lib/model/om/BaseObject.php on line
> > 342
> >
> > How can I use Xdebug to get a stacktrace when the memory exceeds 16M?
>
> If it's enabled and loaded properly, that happens automatically:
>
> derick[@]kossu:~$ php-5.2dev -dmemory_limit=16M -r 'function a() { $a = ""; while( true ) { $a .= "fff"; } } function b() { a(); } b();';
>
> Fatal error: Allowed memory size of 16777216 bytes exhausted at
> /home/derick/dev/php/php-5.2dev/Zend/zend_operators.c:1200 (tried to
> allocate 16514893 bytes) in Command line code on line 1
>
> Call Stack:
> 0.0002 117072 1. {main}() Command line code:0
> 0.0002 117384 2. b() Command line code:1
> 0.0002 117696 3. a() Command line code:1

Much thanks Derick, I tried your example and observe the same results:

ket% php -dmemory_limit=16M -r 'function a() { $a = ""; while( true )
{ $a .= "fff"; } } function b() { a(); } b();';

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to
allocate 16515022 bytes) in Command line code on line 1

Call Stack:
    0.0003 64652 1. {main}() Command line code:0
    0.0003 64772 2. b() Command line code:1
    0.0003 64892 3. a() Command line code:1

ket%

Previously when I was trying to get a stacktrace, I was using PHP CGI
instead of the CLI, so I put your example into a PHP script and tried
with PHP CGI:

<?php

function a() {
  $a = '';
  while (true) {
    $a .= 'fff';
  }
}

function b() {
  a();
}

b();

Sure enough, I see a stacktrace. So there must be some configuration in
the application I am trying to debug which prevents the stacktrace from
being printed.

I see stacktraces for all sorts of notices, but I do not see a message
about the memory exhausted fatal error. Looking in my Apache log, I do
see the memory exhausted fatal error message in there, but I do not see
a stacktrace.

Maybe my application is somehow redirecting errors into the Apache log,
and preventing Xdebug from printing a stacktrace? I will investigate
further...
Received on Wed Nov 26 2008 - 18:22:01 GMT

This archive was generated by hypermail 2.2.0 : Mon Jun 25 2018 - 06:00:04 BST