112

I am using Apache/PHP/MySQL stack.
Using as framework CakePHP.

Every now and then I get a blank white page. I can't debug it through Cake, so I peek in the apache error.log and here's what I get:

[Wed Oct 12 15:27:23 2011] [notice] child pid 3580 exit signal Segmentation fault (11)
[Wed Oct 12 15:27:34 2011] [notice] child pid 3581 exit signal Segmentation fault (11)
[Wed Oct 12 15:30:52 2011] [notice] child pid 3549 exit signal Segmentation fault (11)
[Wed Oct 12 16:04:27 2011] [notice] child pid 3579 exit signal Segmentation fault (11)
zend_mm_heap corrupted
[Wed Oct 12 16:26:24 2011] [notice] child pid 3625 exit signal Segmentation fault (11)
[Wed Oct 12 17:57:24 2011] [notice] child pid 3577 exit signal Segmentation fault (11)
[Wed Oct 12 17:58:54 2011] [notice] child pid 3550 exit signal Segmentation fault (11)
[Wed Oct 12 17:59:52 2011] [notice] child pid 3578 exit signal Segmentation fault (11)
[Wed Oct 12 18:01:38 2011] [notice] child pid 3683 exit signal Segmentation fault (11)
[Wed Oct 12 22:20:53 2011] [notice] child pid 3778 exit signal Segmentation fault (11)
[Wed Oct 12 22:29:51 2011] [notice] child pid 3777 exit signal Segmentation fault (11)
[Wed Oct 12 22:33:42 2011] [notice] child pid 3774 exit signal Segmentation fault (11)

What is this segmentation fault, and how can I fix it?

UPDATE:

PHP Version 5.3.4, OSX local development
Server version: Apache/2.2.17 (Unix)
CakePhp: 1.3.10
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
mgPePe
  • 5,677
  • 12
  • 52
  • 85
  • Need more info on configuration, for example if the versions of php and used modules are up to date and if you use some kind of caching or accelerator. – CodeCaster Oct 12 '11 at 19:44
  • Can you tell me what info you need and how to get it, so I can post it? – mgPePe Oct 12 '11 at 19:48
  • Also check this: http://stackoverflow.com/questions/15689765/apc-and-child-pid-xxxxx-exit-signal-segmentation-fault/15724464#15724464 – trante Jan 23 '14 at 12:01
  • I had a lot of those in my apache logs lately, also segfault (11). Mine were caused by APC and the errors stopped as soon as I disabled APC in php again. But your's could have many other causes. – Meetai.com Mar 23 '14 at 10:46
  • May sound dumb, but I fixed this by simply restarting apache2. – x43 Jan 22 '21 at 14:25

3 Answers3

69

Attach gdb to one of the httpd child processes and reload or continue working and wait for a crash and then look at the backtrace. Do something like this:

$ ps -ef|grep httpd
0     681     1   0 10:38pm ??         0:00.45 /Applications/MAMP/Library/bin/httpd -k start
501   690   681   0 10:38pm ??         0:00.02 /Applications/MAMP/Library/bin/httpd -k start

...

Now attach gdb to one of the child processes, in this case PID 690 (columns are UID, PID, PPID, ...)

$ sudo gdb
(gdb) attach 690
Attaching to process 690.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ....................... done
0x9568ce29 in accept$NOCANCEL$UNIX2003 ()
(gdb) c
Continuing.

Wait for crash... then:

(gdb) backtrace

Or

(gdb) backtrace full

Should give you some clue what's going on. If you file a bug report you should include the backtrace.

If the crash is hard to reproduce it may be a good idea to configure Apache to only use one child processes for handling requests. The config is something like this:

StartServers 1
MinSpareServers 1
MaxSpareServers 1
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57
  • 1
    I've just run into this and it seems when I have gdb attached to a child process I don't get the segfault and apache doesn't ever finish rendering the page. (Reproducing the segfault otherwise is just a matter of hitting refresh as it happens on every reload). It's been awhile since I've worked with closer to the metal toolchains in my C days. I wonder why it might exhibit this behavior. It didn't find a lot of the symbols from my build, but that should just produce a less informative backtrace no? – lucian303 Aug 19 '12 at 18:53
  • Hmm thats weird. Can you make sure that the process that segfaults actually is the on you are attached gdb to? check `dmesg` for the pid of the segfaulted process. – Mattias Wadman Aug 19 '12 at 19:54
  • GDB doesnt work. Gives me `Unable to access task for process-id 70: (os/kern) failure.` – mgPePe Sep 12 '13 at 10:53
  • Is this OSX? maybe check http://stackoverflow.com/questions/11504377/gdb-fails-with-unable-to-find-mach-task-port-for-process-id-error – Mattias Wadman Sep 12 '13 at 12:08
  • the problem is.... which child process? i have at least 10 in my dev machine :) – maxgalbu Feb 27 '14 at 12:45
  • 3
    found the solution: call ```set follow-fork-mode child``` and then attach to the parent process (the one that spawns child processes) -> http://stackoverflow.com/questions/15126925/gdb-debugging-child-process-after-fork-follow-fork-mode-child-configured0 – maxgalbu Feb 27 '14 at 14:48
  • I am also facing similar issue on my server. I tried attaching gdb but it exits without generating any stack trace. The crash happens unpredictably without any pattern in access logs too. I am unable to trace the root of the problem. Any pointers would be helpful. My server is hosted on a small EC2 instance and I use a Bitnami Ubuntu Lampstack AMI without any modifications in Apache server code. – Vishal Apr 10 '14 at 13:19
  • Are you sure gdb is attach to processes that crashes? if gdb just exists it sounds like the attached processes exists normally. Do you see if it exits with some exit code? btw if you get a non useful stack trace try to install debug packages like `apache2-dbg`. – Mattias Wadman Apr 10 '14 at 13:42
  • Actually there are multiple child processes and i tried attaching gdb to different processes but all of them exited normally without any code. Is there any particular child process which needs to be traced? – Vishal Apr 10 '14 at 13:46
  • Did you try to change the apache config so that only one process is running? but are you sure is crashes? if so you should see something i `error.log` about processes existing etc. – Mattias Wadman Apr 10 '14 at 21:49
  • What is gdp? command not found: gdb – Daniel Tate May 02 '16 at 03:50
  • Do you mean gdb? it's the gnu debugger, you might need to install it somehow – Mattias Wadman May 02 '16 at 14:42
  • My problem was that I had an out-dated `mod_http2`! – Geremia Apr 05 '17 at 19:51
27

A segementation fault is an internal error in php (or, less likely, apache). Oftentimes, the segmentation fault is caused by one of the newer and lesser-tested php modules such as imagemagick or subversion.

Try disabling all non-essential modules (in php.ini), and then re-enabling them one-by-one until the error occurs. You may also want to update php and apache.

If that doesn't help, you should report a php bug.

phihag
  • 278,196
  • 72
  • 453
  • 469
  • But how could I know which one it is? – mgPePe Sep 12 '13 at 10:53
  • 1
    For me (on Debian Stretch) it was the Apache module `mod-geoip` - I now use the php geoip-extension instead – Christopher K. Mar 18 '18 at 00:09
  • @mgPePe To find out which one it is, simply disable all non-essential modules (start with all externally developed ones like `mod-geoip`). Does the problem continue? Then disable more. Don't see any segfaults anymore? Enable more modules until you do. If you are technically inclined and have a debugger, see @Mathias Wadmann's excellent answer. Be aware that a debugger can mislead you though - sometimes the crash can be in another module. – phihag Mar 18 '18 at 08:06
  • thank you, disabling not required modules worked for me. – Rao DYC Jul 20 '23 at 06:48
18

Have you tried to increase output_buffering in your php.ini?

What does "zend_mm_heap corrupted" mean?

Community
  • 1
  • 1
Wayne
  • 1,288
  • 1
  • 7
  • 20
  • 4
    I had the same problem on debian squeeze with apache/php/mysql after some update. I set it to `output_buffering = 4096` and now the pages work again. Thx – rubo77 Aug 16 '13 at 15:11
  • 3
    And for me only `output_buffering = 8192` works. Thanks a lot! – Oleg Jan 29 '14 at 16:02
  • 2
    And now, on another page, `output_buffering = 8192` causes segfault, which was fixed by setting `output_buffering = Off`. I'm confused a lot. – Oleg Apr 02 '14 at 15:24
  • 2
    It's years later, but for anyone else that stumbles onto this like I did... I found that turning output buffering off for the server and then making a directory- or file-based edit using an htaccess file was the way to go. Output buffering determines how much data to keep before posting to the user. With small one-liners, this will likely cause an error. In larger files, you risk overloading the process. – Abandoned Cart Oct 22 '18 at 16:59