PHP-FPM提供内置状态页监控后端连接,需在www.conf中配置pm.status_path并用Nginx反向代理暴露;其active processes等指标反映真实FastCGI处理负载,配合Nginx stub_status可实现全链路状态分析。

FastCGI 本身不直接提供连接状态页,Nginx 的 stub_status 模块也**不统计 FastCGI 连接数**——它只反映 Nginx 自身的 HTTP 连接状态(如 Active connections、Reading/Writing/Waiting)。要监控 FastCGI 后端(如 PHP-FPM)的实时连接情况,需转向 PHP-FPM 自带的状态接口,再通过 Nginx 反向代理暴露或直接访问。
确认 PHP-FPM 已启用 status 页面
PHP-FPM 默认禁用状态页,需在它的配置中显式开启:
- 编辑
/etc/php-fpm.d/www.conf(路径依发行版可能为/etc/php/8.2/fpm/pool.d/www.conf) - 确保以下三行未被注释且值正确:
pm.status_path = /statusping.path = /pingping.response = pong - 重启服务:
sudo systemctl reload php-fpm
通过 Nginx 反向代理暴露 PHP-FPM 状态
在 Nginx 的某个 server 块中添加 location,将请求转发给 PHP-FPM 的 status 接口:
- 配置示例(限制仅本地访问):
location /fpm-status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
allow 127.0.0.1;
deny all;
} - 注意:
fastcgi_pass必须与 PHP-FPM 实际监听地址一致(可能是unix:/run/php/php8.2-fpm.sock) - 重载 Nginx:
sudo nginx -t && sudo systemctl reload nginx
获取并解析 FastCGI 连接状态数据
访问 http://localhost/fpm-status?json(或 ?html、?full),返回的是 PHP-FPM 的运行时指标:
-
关键字段说明:
active processes:当前正在处理请求的子进程数idle processes:空闲等待任务的子进程数max active processes:历史峰值start time和start since:服务启动时间与已运行秒数 - 快速提取活跃进程数:
curl -s http://127.0.0.1/fpm-status?json | jq -r '.active processes'
(需安装jq;若无,可用awk或grep -oP 'active processes": \K\d+')
关联分析:Nginx 连接 vs FastCGI 进程
单独看任一指标都不完整。建议交叉比对:
- 执行
curl http://localhost/nginx-status→ 查Active connections - 执行
curl http://localhost/fpm-status?json→ 查active processes - 若 Nginx 连接数高但 PHP-FPM 活跃进程接近
pm.max_children,说明后端已饱和,可能触发 503 或排队延迟 - 若两者都低但用户报慢,问题可能出在数据库、网络或 PHP 脚本逻辑


















