php segfaulting

After today's 'portupgrade -a' my php 5.2.11 started segfaulting on every run. It looks like the segfault happens on exit, and it's very stable - even 'php --version' gives me the following:

Code:
PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Dec  2 2009 12:17:42)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
Segmentation fault (core dumped)

The scripts are executed, webpaged produced by php look fine, but it's very annoying. Yesterday everything was working fine. The ports upgraded today are (the output was produced before portupgrade):

Code:
cups-base-1.4.2             <  needs updating (port has 1.4.2_1) 
cups-client-1.4.2           <  needs updating (port has 1.4.2_1) 
cups-image-1.4.2            <  needs updating (port has 1.4.2_1) 
gobject-introspection-0.6.5  <  needs updating (port has 0.6.5_1) 
libxml2-2.7.6               <  needs updating (port has 2.7.6_1) 
xf86-video-ati-6.12.2_1     <  needs updating (port has 6.12.4)

Nothing else has changed. Oh, yeah, it's 7.0-RELEASE.

Any ideas on what's wrong and how to fix it?
 
Thanks for the advice. The problem disappears if I comment both openssl and curl extensions. Changing the order does not fix it. I'm still looking for a solution.
 
I'd try recompiling the extensions and their dependencies again. Also, if you know how to use gdb (and have a core file) you could try pinpointing the problem there.
 
Rebuilding all extensions is what I'm doing right now.

Using gdb is not a big deal, but I'm probably too lazy for this. :)

Anyway, I'll post my results here.
 
Well, rebuilding the extensions did not work. gdb shows that the problem is in libxml2 (which was updated today):

Code:
#0  0x288e3d50 in ?? ()
#1  0x285b16fb in pthread_once () from /lib/libc.so.7
#2  0x283461d2 in xmlIsMainThread () from /usr/local/lib/libxml2.so.5
#3  0x28345787 in __xmlLastError () from /usr/local/lib/libxml2.so.5
#4  0x282d1847 in xmlResetLastError () from /usr/local/lib/libxml2.so.5
#5  0x282d891f in xmlCleanupParser () from /usr/local/lib/libxml2.so.5
#6  0x080844eb in php_libxml_shutdown ()
#7  0x0808451b in zm_shutdown_libxml ()
#8  0x0814b4ae in module_destructor ()
#9  0x08151804 in zend_hash_apply_deleter ()
#10 0x08151a48 in zend_hash_graceful_reverse_destroy ()
#11 0x08147d2e in zend_shutdown ()
#12 0x0810615f in php_module_shutdown ()
#13 0x081c4100 in main ()

I hope the library will get fixed soon. I think there's a new bad tradition in freebsd - too many updates are breaking some functionality.
 
I'm running the same PHP version with the same extensions and all ports are up to date as of now. On two separate systems serving up stuff like wordpress, roundcube, squirrelmail, etc. No problems here. I think your 'bad tradition' statement is a bit too general .. These forums would be swarming with people complaining had this been a general bug, because this setup is very standard and widely used.
 
Hi,

got the same problem here, on FreeBSD 7.0-p12 and 7.2-RELEASE-p3.

In fact there is no problem with PHP in apache mod. The problem only occurs in CLI mod.
Code:
# php -v
PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Oct 14 2009 17:13:44)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
Segmentation fault (core dumped)

DutchDaemon, can you just try a "php -v" on your servers ?

Using portdowngrade to switch back to the old version of libxml2 (2.7.6) works.

Thanks
 
I've just upgraded all my ports to the latest version. Let's see if I encounter the same problem as well.

If the problem is reproducible, send a PR.

Edit: I don't use CGI though.
 
#1

Code:
PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Nov 16 2009 12:28:30) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
    with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
Code:
eaccelerator-0.9.5.3 An opcode cache for PHP with encoder and loader
libxml2-2.7.6_1     XML parser library for GNOME
openssl-0.9.8l      SSL and crypto library
php-suhosin-0.9.29  A PHP extension that implements high-level protections
php5-5.2.11_1       PHP Scripting Language
php5-ctype-5.2.11_1 The ctype shared extension for php
php5-dom-5.2.11_1   The dom shared extension for php
php5-extensions-1.3 A "meta-port" to install PHP extensions
php5-filter-5.2.11_1 The filter shared extension for php
php5-gd-5.2.11_2    The gd shared extension for php
php5-hash-5.2.11_1  The hash shared extension for php
php5-iconv-5.2.11_1 The iconv shared extension for php
php5-json-5.2.11_1  The json shared extension for php
php5-mbstring-5.2.11_1 The mbstring shared extension for php
php5-mysql-5.2.11_1 The mysql shared extension for php
php5-pcre-5.2.11_1  The pcre shared extension for php
php5-pdo-5.2.11_1   The pdo shared extension for php
php5-pdo_sqlite-5.2.11_1 The pdo_sqlite shared extension for php
php5-posix-5.2.11_1 The posix shared extension for php
php5-session-5.2.11_1 The session shared extension for php
php5-simplexml-5.2.11_1 The simplexml shared extension for php
php5-spl-5.2.11_1   The spl shared extension for php
php5-sqlite-5.2.11_1 The sqlite shared extension for php
php5-tokenizer-5.2.11_1 The tokenizer shared extension for php
php5-xml-5.2.11_1   The xml shared extension for php
php5-xmlreader-5.2.11_1 The xmlreader shared extension for php
php5-xmlrpc-5.2.11_1 The xmlrpc shared extension for php
php5-xmlwriter-5.2.11_1 The xmlwriter shared extension for php
php5-zip-5.2.11_1   The zip shared extension for php
php5-zlib-5.2.11_1  The zlib shared extension for php
roundcube-0.3.1,1   Fully skinnable XHTML/CSS webmail written in PHP

#2
Code:
PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Nov 19 2009 18:08:48)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
    with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
Code:
eaccelerator-0.9.5.3 An opcode cache for PHP with encoder and loader
libmcrypt-2.5.8     Multi-cipher cryptographic library (used in PHP)
libxml2-2.7.6_1     XML parser library for GNOME
openssl-0.9.8l      SSL and crypto library
php-suhosin-0.9.29  A PHP extension that implements high-level protections
php5-5.2.11_1       PHP Scripting Language
php5-bz2-5.2.11_1   The bz2 shared extension for php
php5-calendar-5.2.11_1 The calendar shared extension for php
php5-ctype-5.2.11_1 The ctype shared extension for php
php5-curl-5.2.11_1  The curl shared extension for php
php5-dom-5.2.11_1   The dom shared extension for php
php5-extensions-1.3 A "meta-port" to install PHP extensions
php5-filter-5.2.11_1 The filter shared extension for php
php5-ftp-5.2.11_1   The ftp shared extension for php
php5-gd-5.2.11_2    The gd shared extension for php
php5-gettext-5.2.11_1 The gettext shared extension for php
php5-hash-5.2.11_1  The hash shared extension for php
php5-iconv-5.2.11_1 The iconv shared extension for php
php5-imap-5.2.11_1  The imap shared extension for php
php5-json-5.2.11_1  The json shared extension for php
php5-mbstring-5.2.11_1 The mbstring shared extension for php
php5-mcrypt-5.2.11_1 The mcrypt shared extension for php
php5-mhash-5.2.11_1 The mhash shared extension for php
php5-mysql-5.2.11_1 The mysql shared extension for php
php5-openssl-5.2.11_1 The openssl shared extension for php
php5-pcre-5.2.11_1  The pcre shared extension for php
php5-pdo-5.2.11_1   The pdo shared extension for php
php5-pdo_sqlite-5.2.11_1 The pdo_sqlite shared extension for php
php5-posix-5.2.11_1 The posix shared extension for php
php5-session-5.2.11_1 The session shared extension for php
php5-simplexml-5.2.11_1 The simplexml shared extension for php
php5-spl-5.2.11_1   The spl shared extension for php
php5-sqlite-5.2.11_1 The sqlite shared extension for php
php5-tokenizer-5.2.11_1 The tokenizer shared extension for php
php5-xml-5.2.11_1   The xml shared extension for php
php5-xmlreader-5.2.11_1 The xmlreader shared extension for php
php5-xmlwriter-5.2.11_1 The xmlwriter shared extension for php
php5-zip-5.2.11_1   The zip shared extension for php
php5-zlib-5.2.11_1  The zlib shared extension for php
phpMyAdmin-3.2.3    A set of PHP-scripts to manage MySQL over the web
phpmailer-5.1       Full Featured Email Transfer Class for PHP
roundcube-0.3.1,1   Fully skinnable XHTML/CSS webmail written in PHP
 
This is an isolated to your server, otherwise we got more messages on freebsd mailing lists. PHP is widely used. Did you recently upgraded from older version?
Code:
PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Oct 25 2009 09:48:29) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with XCache v1.3.0, Copyright (c) 2005-2009, by mOo

This box serving around 4 to 5 million page views per month.
 
Giraya said:
No more segmentation fault if I remove theses lines from the "patch-configure" file of the libxml2 port

Thanks, but - nope. Just tried it - my php is still coredumping after removing these lines and rebuilding the library.

I suspect that the problem is not just in the library, but in the combination of php extensions which use it. What helps on one machine may not work on another.
 
I'm having segfault since today too.. mine disappear when I comment out the mhash, memcached and gearman extensions, which I really need.

I've done everything I can think of, including running portmanager -u to update everything, but the problem remains.

Any help would be very very appreciated. I've been trying to get this sorted all day now..
 
kalobok said:
What helps on one machine may not work on another.

OK, but it's strange, because I have multiple servers with different configurations (and kernels) and this modification works on each one.
 
Giraya said:
OK, but it's strange, because I have multiple servers with different configurations (and kernels) and this modification works on each one.

Something strange is happening. I rebuilt and reinstalled the library again and the segfault is now gone. I'll try to reproduce this again - maybe I missed something during the first try.

Thanks for the fix.
 
The only difference that makes (in config.log) is:

Code:
< THREAD_LIBS=''
---
> THREAD_LIBS='-pthread'

and
Code:
< XML_LIBS='-lxml2 -lz  -L/usr/local/lib -liconv -lm '
---
> XML_LIBS='-lxml2 -lz -pthread -L/usr/local/lib -liconv -lm '

So you're adding -pthread to the compilation. I don't see the immediate impact.

Edit: oh, I see it didn't make a real difference. So that was expected ;)
 
Ok, I checked it again and can confirm: the Giraya's method is working. No more segfaults.

The bug is definitely related to thread-safety (see the stack trace above). Maybe the difference is in php configuration. Mine has "Thread Safety => disabled". Maybe thread-safe php does not have the problem.
 
Removing the THREAD_LIBS="" line from the patch-configure file fixed the PHP (and perl*) problem for me, as well.

* yesterday, not only PHP started to act weirdly, but perl suddenly segfaulting whenever I both created an XML parser and opened a connection to my PostgreSQL database.
 
kalobok said:
Well, rebuilding the extensions did not work. gdb shows that the problem is in libxml2 (which was updated today):

Code:
#0  0x288e3d50 in ?? ()
#1  0x285b16fb in pthread_once () from /lib/libc.so.7
#2  0x283461d2 in xmlIsMainThread () from /usr/local/lib/libxml2.so.5
#3  0x28345787 in __xmlLastError () from /usr/local/lib/libxml2.so.5
#4  0x282d1847 in xmlResetLastError () from /usr/local/lib/libxml2.so.5
#5  0x282d891f in xmlCleanupParser () from /usr/local/lib/libxml2.so.5
#6  0x080844eb in php_libxml_shutdown ()
#7  0x0808451b in zm_shutdown_libxml ()
#8  0x0814b4ae in module_destructor ()
#9  0x08151804 in zend_hash_apply_deleter ()
#10 0x08151a48 in zend_hash_graceful_reverse_destroy ()
#11 0x08147d2e in zend_shutdown ()
#12 0x0810615f in php_module_shutdown ()
#13 0x081c4100 in main ()

I hope the library will get fixed soon. I think there's a new bad tradition in freebsd - too many updates are breaking some functionality.

I have the exact same bug in my core dump.

kalobok said:
Ok, I checked it again and can confirm: the Giraya's method is working. No more segfaults.

The bug is definitely related to thread-safety (see the stack trace above). Maybe the difference is in php configuration. Mine has "Thread Safety => disabled". Maybe thread-safe php does not have the problem.

Giraya's fix works for me to. Finally up and running again ;)
 
Back
Top