Project

General

Profile

how to debug crash of php running under spawn-fcgi?

Added by charlie almost 14 years ago

Hi,

At some point this morning, the PHP process I had spawned using spawn-fcgi (1.6.3) on my new Centos5.5 server died (I'm hosting a wordpress blog). I'm having trouble figuring out how to debug what went wrong; there's no information in /var/log/php/error.log, or anywhere else that I can see. I'm brand new to spawn-fcgi, and haven't worked with a PHP app in a very long time, so I'm wondering if someone here might be able to point me in the right direction to diagnose and fix this. If this forum is not the right place to turn for help with this, I apologize.

Here are the two HTTP requests from nginx access.log on either side of the crash:

193.164.138.35 - - [23/Jun/2011:10:36:57 -0700] "GET /feed/ HTTP/1.1" 200 71394 "-" "Zemanta Aggregator/0.7 +http://www.zemanta.com" "-" http 1.353
193.164.138.35 - - [23/Jun/2011:10:37:09 -0700] "GET /feed/ HTTP/1.1" 502 173 "-" "Zemanta Aggregator/0.7 +http://www.zemanta.com" "-" http 0.000

The /feed/ URL has been re-requested many times since then without incident; so it's not obviously to blame.

I am reverse-proxying PHP using spawn-fcgi behind nginx. Here's /etc/sysconfig/spawn-fcgi:

OPTIONS="-u nobody -g nobody -a 127.0.0.1 -p 53217 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"

Here's how /etc/init.d/spawn-fcgi launches spawn.fcgi:

exec="/usr/bin/spawn-fcgi" 
prog="spawn-fcgi" 
config="/etc/sysconfig/spawn-fcgi" 

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    echo -n $"Starting $prog: " 
    # Just in case this is left over with wrong ownership
    [ -n "${SOCKET}" -a -S "${SOCKET}" ] && rm -f ${SOCKET}
    daemon "$exec $OPTIONS >/dev/null" 
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

Error reporting in php.ini is set to E_ALL (I do see warnings in /var/log/php/error.log).

I installed nginx, spawn-fcgi and php from RPMs in the EPEL repository.

[root@la1 new]# /usr/bin/spawn-fcgi -v
spawn-fcgi v1.6.3 (ipv6) - spawns FastCGI processes
Build-Date: May 25 2010 12:33:48

[root@la1 new]# /usr/sbin/nginx -V
nginx version: nginx/0.8.54
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
TLS SNI support disabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx \
 --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf \
 --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \
 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
 --http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
 --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
 --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
 --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid \
 --lock-path=/var/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module \
 --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module \
 --with-http_geoip_module --with-http_sub_module --with-http_dav_module \
 --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module \
 --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module \
 --with-http_perl_module --with-mail --with-file-aio --with-mail_ssl_module --with-ipv6 \
 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \
 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

[root@la1 new]# /usr/bin/php-cgi -v
PHP 5.1.6 (cgi-fcgi) (built: Nov 29 2010 16:43:56)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

Finally, here's the relevant nginx.conf stuff (real pathnames omitted, but they do work, as you can see if you go to blog.storitz.com):

  upstream php {
    server 127.0.0.1:53217;
  }
  server {
    listen 80;
    server_name blog.storitz.com;
    access_log  /path/to/blog.storitz.com/access.log  main;
    root /path/to/wordpress;
    index index.php;
    location ~ ^/(?P<script>.+\.php)(?P<path_info>.*)$ {
      include fastcgi.conf;
      fastcgi_param SCRIPT_FILENAME $document_root$script;
      fastcgi_param SCRIPT_NAME $script;
      fastcgi_param PATH_INFO $path_info;
      fastcgi_pass php;
    }
    location ~ ^/ { # support prettier permalinks; inject "index.php" into path
      try_files $uri $uri/ /index.php$args;
    }
  }

Replies (2)

RE: how to debug crash of php running under spawn-fcgi? - Added by stbuehler almost 14 years ago

a) this is the reason why we recommend running spawn-fcgi under a supervisor which will restart your crashed php: Basic_Ideas
b) you could attach to the running php process with strace or gdb (option -p + process id)

RE: how to debug crash of php running under spawn-fcgi? - Added by charlie almost 14 years ago

Thanks -- I will switch to using daemontools. (Is it common for one's PHP process to crash like that?)

    (1-2/2)