request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www-slow.log
<?php echo 「test slow log」; sleep(2);echo 「done」; ?>
request_slowlog_timeout = 1 //超過一秒鐘就要記錄日誌 slowlog = /usr/local/php-fpm/var/log/www-slow.log //日誌放到該路徑下
最終以下php
[root@hanfeng php-fpm.d]# vim www.conf [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www-slow.log 保存退出
[root@hanfeng php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t [10-Jan-2018 00:04:26] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [root@hanfeng php-fpm.d]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@hanfeng php-fpm.d]#
[root@hanfeng php-fpm.d]# ls /usr/local/php-fpm/var/log/ php-fpm.log www-slow.log [root@hanfeng php-fpm.d]#
[root@hanfeng php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log [root@hanfeng php-fpm.d]#
[root@hanfeng php-fpm.d]# vim /data/wwwroot/test.com/sleep.php 加入php休眠兩秒鐘,故意讓它執行慢 <?php echo 「test slow log」; sleep(2);echo 「done」; ?> 保存退出
[root@hf-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php [root@hf-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I HTTP/1.1 500 Internal Server Error Server: nginx/1.12.1 Date: Tue, 09 Jan 2018 21:47:48 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30 [root@hf-01 php-fpm.d]#
[root@hf-01 php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini 搜索 /display ,找到display_errors 將display_errors = Off 改成display_errors = On
[root@hf-01 php-fpm.d]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@hf-01 php-fpm.d]#
[root@hf-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php <br /> <b>Parse error</b>: syntax error, unexpected 'slow' (T_STRING), expecting ',' or ';' in <b>/data/wwwroot/test.com/sleep.php</b> on line <b>2</b><br /> [root@hf-01 php-fpm.d]#
[root@hf-01 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php <?php echo "test slow log"; sleep(2); echo "done"; ?> 保存退出 [root@hf-01 php-fpm.d]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@hf-01 php-fpm.d]#
[root@hf-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php test slow logdone[root@hf-01 php-fpm.d]#
[root@hf-01 php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log [10-Jan-2018 06:02:21] [pool www] pid 3442 script_filename = /data/wwwroot/test.com/sleep.php //提示:是哪一個腳本慢 [0x00007f37c5f7c298] sleep() /data/wwwroot/test.com/sleep.php:3 //提示:是腳本的第三慢 [root@hf-01 php-fpm.d]#
[root@hf-01 php-fpm.d]# cat www.conf [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 //通常寫兩秒,不少腳本都會超過一秒 slowlog = /usr/local/php-fpm/var/log/www-slow.log [root@hf-01 php-fpm.d]#