我开始鄙视PHP-FPM! 这在处理错误方面是非常可怕的!
我得到一个NetworkError: 502 Bad Gateway
,虽然我知道错误发生的地方,因为我手动取消评论逐行,直到我发现坏行,我不知道为什么那行是造成问题。
在你问什么是导致错误的行之前,这不是我的问题,我的问题是,我不能让PHP告诉我错误是什么。 它只是继续响应一个502错误。
这是我的configuration
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
将是很好的!
进程退出信号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。 对于所有进程的自动跟踪添加到配置:
xdebug.auto_trace=On
你会得到痕迹,默认路径是:
xdebug.trace_output_dir => /tmp => /tmp xdebug.trace_output_name => trace.%c => trace.%c
所以你的跟踪将有名称/tmp/trace.$PID.xt
在进程崩溃之前,您应该能够看到最后一次调用的功能。