php-fpm中的错误502没有任何细节

时间:2014-10-02 14:49:01

标签: php nginx

我开始鄙视PHP-FPM!它在处理错误方面很可怕!

我得到一个NetworkError: 502 Bad Gateway,虽然我知道错误发生在哪里,因为我手动逐行注释,直到找到坏线,我不知道为什么这条线导致了问题。

在你问这个导致错误的行是什么之前,这不是我的问题,我的问题是我无法让PHP告诉我错误是什么。它只是响应502错误。

这是我的配置

nginx网站

location ~ .+?\.php {
    fastcgi_split_path_info ^(.+?\.php)/?(.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param LOG_PATH /var/www/sites/api/logs;
    fastcgi_param ENVIRONMENT dev;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 254 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    proxy_intercept_errors on;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
}

的php.ini

[PHP]
engine = On
expose_php = Off
max_execution_time = 30
memory_limit = 128M
default_socket_timeout = 5
session.save_path = /var/www/session/
file_uploads = Off
upload_tmp_dir = /tmp/php
upload_max_filesize = 5M
post_max_size = 5M
max_file_uploads = 1
date.timezone = 'UTC'
disable_functions = phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
mail.add_x_header = Off
sql.safe_mode = On
cgi.force_redirect = 1
allow_url_fopen = Off
allow_url_include = Off

error_reporting = E_ALL
display_errors = On
display_startup_errors = On
html_errors = Off
log_errors = On
error_log = /var/log/php5-fpm.log
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On

pool.d / www.conf

[www]
listen = /var/run/php5-fpm.sock
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data

pm = static
pm.max_children = 600
;pm.start_servers = 10
;pm.min_spare_servers = 5
;pm.max_spare_servers = 15
pm.max_requests = 100
;pm.status_path = /php_status

;request_terminate_timeout = 5s
;request_slowlog_timeout = 5s
;slowlog = /var/log/php/fpm/domain.slowlog.log

; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Default Value: no
catch_workers_output = yes

php_flag[display_errors] = on
php_flag[display_startup_errors] = on
;php_flag[output_buffering] = off

php_admin_value[error_log] = /var/log/php5-fpm.log
php_admin_flag[log_errors] = on

以及我在日志中获得的所有内容如下

网站错误日志

2014/10/02 14:34:50 [error] 25966#0: *9 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 109.70.40.213, server: www.example.com, request: "POST /v2/payments/payment/sale HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.example.cm", referrer: "http://boxshop.im/checkout"

php错误日志

[02-Oct-2014 14:44:26.023450] DEBUG: pid 25216, fpm_event_loop(), line 419: event module triggered 2 events
[02-Oct-2014 14:44:26.023927] DEBUG: pid 25216, fpm_got_signal(), line 76: received SIGCHLD
[02-Oct-2014 14:44:26.024044] WARNING: pid 25216, fpm_children_bury(), line 252: [pool www] child 25251 exited on signal 11 (SIGSEGV) after 1441.610042 seconds from start 
[02-Oct-2014 14:44:26.025943] NOTICE: pid 25216, fpm_children_make(), line 421: [pool www] child 26039 started 
[02-Oct-2014 14:44:26.026192] DEBUG: pid 25216, fpm_event_loop(), line 419: event module triggered 1 events

一个不错的,Parse Error on line 234会很好!

沮丧

1 个答案:

答案 0 :(得分:8)

进程退出singal 11(分段错误)。通常,它意味着进程意外崩溃,因为内存使用中的一些错误,并且php无法以任何方式处理该错误。您将使用apache + mod_php,apache + mod_fcgid或任何其他配置获得相同的错误。

在我的实践中,segfault在所有配置中都没有给出有用的错误消息。调试它的唯一真正方法是 strace 。用于将strace附加到运行的所有php进程的单行程序:

strace -f -F -s1000 -t -T `ps aux | grep -E 'apache|php|httpd' | awk '{print "-p" $2}' | xargs`

如果错误很难重现,可以使用 xdebug php-module。 你需要安装它:

apt-get install php5-xdebug

yum install php-pecl-xdebug

对于CentOS。 对于所有进程的自动跟踪,添加到config:

xdebug.auto_trace=On

你会得到痕迹,默认路径是:

xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c

因此,您的跟踪将具有名称/tmp/trace.$PID.xt

你应该能够在进程崩溃之前看到最后一次调用功能。