在你的 php-fpm 日志文件中,你应该能够看到如下内容:
WARNING: [pool www-images] server reached pm.max_children setting (5), consider raising it.
当活动进程数达到限制时。您应该能够将其与传入的请求相关联。
如果这没有显示导致问题的任何请求的模式,那么您应该将慢速日志记录添加到php-fpm配置中:
request_slowlog_timeout = 10
slowlog = /var/log/php-fpm/slow.$pool.log
将记录占用超过 slowlog_timeout 限制的每个请求的堆栈跟踪。
如果这仍然没有显示任何内容,那么您的内部应用程序日志记录应该显示减速发生的位置。
如果没有足够的细节,那么您可以使用strace作为最后的手段,这将显示正在进行哪些系统调用。这将产生大量信息。我建议只将其附加到单个进程,其中PID是php-fpm实例的processID。strace -p PID
它也可能发生在当天流量计数最低的情况下。
这绝对应该出现在php-fpm慢速日志记录中。但是,如果这只显示什么请求很慢,但不能帮助你找出原因,你可以在 PHP-FPM 配置文件中使用自动预置和后置文件添加调试。
php_value[auto_prepend_file]=/php_shared/prepend.php
php_value[auto_append_file]=/php_shared/postpend.php
或者真的很简单
您可以设置 PHP-FPM 状态页面。
将其添加到 PHP-FPM 池配置中:
pm.status_path = /www-status
并通过nginx将请求传递给PHP-FPM
location ~ ^/(www-status)$ {
include %mysite.root.directory%/conf/fastcgi.conf;
fastcgi_pass unix:%phpfpm.socket%/php-fpm-www.sock;
# or IP address
# fastcgi_pass 127.0.0.1:9000;
#If you're fastcgi.conf doesn't set the query_string
#pass the query string here instead.
# fastcgi_param QUERY_STRING $query_string;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
allow 127.0.0.1;
allow stats_collector.localdomain;
allow watchdog.localdomain;
deny all;
}
然后转到 yoursite.com/www-status?full 将为您提供每个php-fpm进程的大打印输出,例如:
pool: www
process manager: dynamic
start time: 18/Mar/2013:20:17:21 +1100
start since: 243
accepted conn: 3
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 3
active processes: 1
total processes: 4
max active processes: 1
max children reached: 0
slow requests: 0
************************
pid: 6233
state: Idle
start time: 18/Mar/2013:20:17:21 +1100
start since: 243
requests: 1
request duration: 631
request method: GET
request URI: /www-status
content length: 0
user: -
script: /documents/projects/intahwebz/intahwebz/basereality/www-status
last request cpu: 0.00
last request memory: 262144
顺便说一句,我敢打赌,这是一些愚蠢的查询,它锁定了你的数据库。