Segmentation fault: 11 (core dumped) in php on Freebsd

Oh, I finally got time for some coding and server updates. Sadly but interestering I got this strange error after updating php5 (/usr/ports/lang/php5) to the latest in the Freebsd ports tree.

The error:
/usr/local> php -v
PHP Fatal error: PHP Startup: apc_shm_create: shmget(0, 31457280, 914) failed: Cannot allocate memory. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment. in Unknown on line 0
PHP Fatal error: PHP Startup: apc_shm_attach: shmat failed: in Unknown on line 0
Segmentation fault: 11 (core dumped)

The first problem was the ”PHP Fatal error” lines that has something to do with APC cache. This was solved by:
/usr/ports/www/pecl-APC> make config
Then I unticked the "IPC Enable IPC shm memory support (default: mmap)" line. Don't really know what it does....
/usr/ports/www/pecl-APC> make deinstall
/usr/ports/www/pecl-APC> make clean
/usr/ports/www/pecl-APC> make install clean

The second problem was the ”Segmentation fault: 11 (core dumped)” line which caused a core dump each time php ran (a php.core file is produced). This was a bit strange. To investigate why it crashes I used gdb on the core file. A core file contains the in-memory state of the program at the time it crashes.

/usr/local/lib/php> gdb /usr/local/bin/php php.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `php'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libcrypt.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypt.so.4
Reading symbols from /usr/local/lib/libpcre.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpcre.so.0
Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.5
Reading symbols from /usr/local/lib/libxml2.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxml2.so.5
Reading symbols from /lib/libz.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libz.so.4
Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libiconv.so.3
Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.7
Reading symbols from /usr/local/lib/php/libs/curl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/curl.so
Reading symbols from /usr/local/lib/libcurl.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libcurl.so.6
Reading symbols from /usr/lib/libssl.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libssl.so.5
Reading symbols from /lib/libcrypto.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypto.so.5
Reading symbols from /usr/local/lib/php/libs/iconv.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/iconv.so
Reading symbols from /usr/local/lib/php/libs/json.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/json.so
Reading symbols from /usr/local/lib/php/libs/exif.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/exif.so
Reading symbols from /usr/local/lib/php/libs/ftp.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ftp.so
Reading symbols from /usr/local/lib/php/libs/openssl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/openssl.so
Reading symbols from /usr/local/lib/php/libs/hash.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/hash.so
Reading symbols from /usr/local/lib/php/libs/bz2.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/bz2.so
Reading symbols from /usr/lib/libbz2.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libbz2.so.3
Reading symbols from /usr/local/lib/php/libs/mysql.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/mysql.so
Reading symbols from /usr/local/lib/php/libs/tokenizer.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/tokenizer.so
Reading symbols from /usr/local/lib/php/libs/simplexml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/simplexml.so
Reading symbols from /usr/local/lib/php/libs/xml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xml.so
Reading symbols from /usr/local/lib/php/libs/posix.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/posix.so
Reading symbols from /usr/local/lib/php/libs/dom.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/dom.so
Reading symbols from /usr/local/lib/php/libs/gd.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/gd.so
Reading symbols from /usr/local/lib/libt1.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libt1.so.5
Reading symbols from /usr/local/lib/libfreetype.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libfreetype.so.9
Reading symbols from /usr/local/lib/libX11.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libX11.so.6
Reading symbols from /usr/local/lib/libXpm.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXpm.so.4
Reading symbols from /usr/local/lib/libpng.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpng.so.6
Reading symbols from /usr/local/lib/libjpeg.so.11...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libjpeg.so.11
Reading symbols from /usr/local/lib/libxcb.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxcb.so.2
Reading symbols from /usr/lib/librpcsvc.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/librpcsvc.so.4
Reading symbols from /usr/local/lib/libXau.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXau.so.6
Reading symbols from /usr/local/lib/libXdmcp.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXdmcp.so.6
Reading symbols from /usr/local/lib/libpthread-stubs.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpthread-stubs.so.0
Reading symbols from /usr/local/lib/php/libs/xmlreader.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlreader.so
Reading symbols from /usr/local/lib/php/libs/xmlwriter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlwriter.so
Reading symbols from /usr/local/lib/php/libs/sockets.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sockets.so
Reading symbols from /usr/local/lib/php/libs/zlib.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/zlib.so
Reading symbols from /usr/local/lib/php/libs/session.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/session.so
Reading symbols from /usr/local/lib/php/libs/soap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/soap.so
Reading symbols from /usr/local/lib/php/libs/xsl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xsl.so
Reading symbols from /usr/local/lib/libexslt.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libexslt.so.8
Reading symbols from /usr/local/lib/libxslt.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxslt.so.2
Reading symbols from /usr/local/lib/libgcrypt.so.17...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgcrypt.so.17
Reading symbols from /usr/local/lib/libgpg-error.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgpg-error.so.0
Reading symbols from /usr/local/lib/libintl.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libintl.so.9
Reading symbols from /usr/local/lib/php/libs/sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite.so
Reading symbols from /usr/local/lib/php/libs/pdo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo.so
Reading symbols from /usr/local/lib/php/libs/pdo_sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo_sqlite.so
Reading symbols from /usr/local/lib/libsqlite3.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libsqlite3.so.8
Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/libthr.so.3
Reading symbols from /usr/local/lib/php/libs/xmlrpc.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlrpc.so
Reading symbols from /usr/local/lib/php/libs/ctype.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ctype.so
Reading symbols from /usr/local/lib/php/libs/fileinfo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/fileinfo.so
Reading symbols from /usr/local/lib/php/libs/filter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/filter.so
Reading symbols from /usr/local/lib/php/libs/imap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/imap.so
Reading symbols from /usr/local/lib/libc-client4.so.9...done.
Loaded symbols for /usr/local/lib/libc-client4.so.9
Reading symbols from /usr/lib/libpam.so.4...done.
Loaded symbols for /usr/lib/libpam.so.4
Reading symbols from /usr/local/lib/php/libs/mbstring.so...done.
Loaded symbols for /usr/local/lib/php/libs/mbstring.so
Reading symbols from /usr/local/lib/libonig.so.1...done.
Loaded symbols for /usr/local/lib/libonig.so.1
Reading symbols from /usr/local/lib/php/libs/sqlite3.so...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite3.so
Reading symbols from /usr/local/lib/php/libs/zip.so...done.
Loaded symbols for /usr/local/lib/php/libs/zip.so
Reading symbols from /usr/local/lib/php/libs/apc.so...done.
Loaded symbols for /usr/local/lib/php/libs/apc.so
Reading symbols from /usr/lib/librt.so.1...done.
Loaded symbols for /usr/lib/librt.so.1
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0 0x0000000805de1f5d in apc_sma_init () from /usr/local/lib/php/libs/apc.so
[New Thread 0x801533120 (LWP 100263)]

Ok, I smell some fish here. Then i checked the ”stack backtrace” with bt.

(gdb) bt
#0 0x0000000804c7c8c0 in ?? ()
#1 0x00000008042e1bc4 in xsltUnregisterExtModuleFunction () from /usr/local/lib/libxslt.so.2
#2 0x00000008040adc97 in zm_shutdown_xsl () from /usr/local/lib/php/libs/xsl.so
#3 0x000000000055e2cf in module_destructor ()
#4 0x000000000056597a in zend_hash_apply_deleter ()
#5 0x0000000000565be8 in zend_hash_graceful_reverse_destroy ()
#6 0x00000000005596f7 in zend_shutdown ()
#7 0x00000000005045f5 in php_module_shutdown ()
#8 0x00000000005e505f in main ()
#9 0x00000000004189e5 in _start ()
#10 0x0000000800786000 in ?? ()

The problem was clearly related to one of my php-extensions /usr/local/lib/php/libs/xsl.so. Then I tried not to use this extension by uncomment it in /usr/local/etc/php/extensions.ini. However I got similiar error in another extension by doing that. There must be some other error that hasn’t with my extensions to do…

With some google fu I found this post which explains the problem. Some extensions are threaded while php5 isn’t by default. To make php threaded you have to configure it to be so. That’s fairly easy in Freebsd.

/usr/ports/lang/php5/make config
Tick the "LINKTHR Link thread lib (for threaded extensions)" option.
/usr/ports/lang/php5/make deinstall
/usr/ports/lang/php5/make clean
/usr/ports/lang/php5/make install clean

Then i restarted my apache server, typed ”php -m” and everything looked fine, not one single strange error message. Yieeehaa!!

En kommentar till “Segmentation fault: 11 (core dumped) in php on Freebsd”

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *

Denna webbplats använder Akismet för att minska skräppost. Lär dig hur din kommentardata bearbetas.