用PHP-FPM 的 slow log 分析网站

本文介绍如何通过启用PHP-FPM慢执行日志来诊断并解决网站响应速度慢的问题。通过具体示例展示了如何配置及解读慢日志文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近从GOOGLE ananlytics 发现网站速度变慢了很多,  于是想到了PHP中的FPM慢日志功能。

好在 PHP-FPM 提供了慢执行日志,可以将执行比较慢的脚本的调用过程 dump 到日志中。

 

 

cd /etc/php5/fpm/pool.d/
vi www.conf

 修改配置

 

 

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_slowlog_timeout = 1s

; The log file for slow requests
; Default Value: /usr/local/php/log/php-fpm.log.slow
slowlog = /usr/local/php/log/php-fpm.log.slow

 

 

 

加上慢执行日志后,我们可以很容易从慢执行日志中看出问题所在,比如:

 

[13-May-2013 05:17:12]  [pool www] pid 13557                                                                                                                    
script_filename = /opt/www/inkebook/index.php                                                                                                                   
[0x000000000292e0f0] commit() /opt/www/inkebook/includes/database/mysql/database.inc:166                                                                        
[0x000000000292de88] popCommittableTransactions() /opt/www/inkebook/includes/database/database.inc:1128                                                         
[0x000000000292dcf0] popTransaction() /opt/www/inkebook/includes/database/database.inc:1905                                                                     
[0x00007fffe78cc460] __destruct() unknown:0                                                                                                                     
[0x000000000292c690] execute() /opt/www/inkebook/modules/statistics/statistics.module:73                                                                        
[0x00007fffe78cc900] statistics_exit() unknown:0                                                                                                                
[0x000000000292c208] call_user_func_array() /opt/www/inkebook/includes/module.inc:857                                                                           
[0x000000000292bf10] module_invoke_all() /opt/www/inkebook/includes/common.inc:2688                                                                             
[0x000000000292ade0] drupal_page_footer() /opt/www/inkebook/includes/common.inc:2676                                                                            
[0x000000000292aa28] drupal_deliver_html_page() /opt/www/inkebook/includes/common.inc:2560                                                                      
[0x000000000292a378] drupal_deliver_page() /opt/www/inkebook/includes/menu.inc:532                                                                              
[0x000000000292a198] menu_execute_active_handler() /opt/www/inkebook/index.php:21                                                                               

 再进行进一步的程序分析,就更具方向性了。

 

 

欢迎访问下面网站, 下载电子书

http://www.inkebook.com/

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值