排查:
1.查看php-fpm慢日志slowlog指向链接
2.查看php-fpm日志是否有错误或警告日志
解决:
1.调整php-fpm.conf中max_children配置
2.把耗时的网络IO(curl)或磁盘IO请求独立出来
2.1)新增一个php-fpm端口为9001的进程池,专门用了处理耗时的请求
2.2)nginx把耗时的处理转发到9001的端口上
php-fpm.conf配置
#php-fpm.conf: 正常脚本由静态www池处理,阻塞脚本由动态curl池处理 [www] listen = 127.0.0.1:9000 pm = static pm.max_children = 4 [curl] listen = 127.0.0.1:9001 pm = dynamic pm.max_children = 8 pm.start_servers = 4 pm.min_spare_servers = 4 pm.max_spare_servers = 6
nginx.cof配置
#nginx.conf: 访问curl.php的请求都交给监听9001的PHP-FPM进程池处理 location = /curl.php { include fastcgi_params; fastcgi_pass 127.0.0.1:9001; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
这样耗时的进程就不会影响计算的进程,有效时阻止502状态出现