Environment description
root@ubuntu:/home/tb# cat /etc/issue Ubuntu 16.04.2 LTS \n \l root@ubuntu:/home/tb# php -v PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies
View the last line of the php-fpm configuration path
root@ubuntu:/home/tb# ps -ef |grep fpm root 1642 1 0 10:17 ? 00:00:01 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf) www-data 3685 1642 0 17:14 ? 00:00:04 php-fpm: pool www www-data 3686 1642 0 17:14 ? 00:00:03 php-fpm: pool www www-data 3808 1642 0 17:43 ? 00:00:03 php-fpm: pool www root 3930 2208 0 18:10 pts/0 00:00:00 grep --color=auto fpm root@ubuntu:/home/tb#
php-fpm.conf
include=/etc/php/7.0/fpm/pool.d/*.conf
Then we Go there and change www.conf
, and check the introduction about slow query
314 ; The log file for slow requests 315 ; Default Value: not set 316 ; Note: slowlog is mandatory if request_slowlog_timeout is set 317 ;slowlog = log/$pool.log.slow 318 319 ; The timeout for serving a single request after which a PHP backtrace will be 320 ; dumped to the 'slowlog' file. A value of '0s' means 'off'. 321 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) 322 ; Default Value: 0 323 ;request_slowlog_timeout = 0
Add two lines of configuration
slowlog=/var/log/php7.0/fpm/slow.log request_slowlog_timeout=1s
Restart fpm, and pay attention to general issues such as directory permissions
service php7.0-fpm reload
View log echo results
[03-Jan-2018 18:48:53] [pool www] pid 4934 script_filename = /usr/share/nginx/ testapp/index.php [0x00007fb626213520] session_start() /usr/share/nginx/ testapp/app/models/user_model.php:11 [0x00007fb6262134a0] __construct() /usr/share/nginx/ci_2.2.0/core/Loader.php:303 [0x00007fb626213390] model() /usr/share/nginx/ testapp/app/core/my_Controller.php:39 [0x00007fb6262132e0] __construct() /usr/share/nginx/ testapp/app/controllers/home.php:8 [0x00007fb626213270] __construct() /usr/share/nginx/ci_2.2.0/core/CodeIgniter.php:308 [0x00007fb6262130e0] [INCLUDE_OR_EVAL]() /usr/share/nginx/ testapp/index.php:325 [03-Jan-2018 18:48:53] [pool www] pid 4931 script_filename = /usr/share/nginx/ testapp/index.php [0x00007fb626213520] session_start() /usr/share/nginx/ testapp/app/models/user_model.php:11 [0x00007fb6262134a0] __construct() /usr/share/nginx/ci_2.2.0/core/Loader.php:303 [0x00007fb626213390] model() /usr/share/nginx/ testapp/app/core/my_Controller.php:39 [0x00007fb6262132e0] __construct() /usr/share/nginx/ testapp/app/controllers/home.php:8 [0x00007fb626213270] __construct() /usr/share/nginx/ci_2.2.0/core/CodeIgniter.php:308 [0x00007fb6262130e0] [INCLUDE_OR_EVAL]() /usr/share/nginx/ testapp/index.php:325
Explanation about log
[03-Jan-2018 18:48:53] [pool www] pid 4931
There is no explanation for this, time process id
script_filename = /usr/share/nginx/ testapp/index.php
Execution script name, php web application For single entry
[0x00007fb626213520] session_start() /usr/share/nginx/ testapp/app/models/user_model.php:11
This third line is more important: it is the top of the stack trace. It indicates which function call of the currently executed method exceeds the threshold, and Specific files and lines of code
The remaining part is the order of calls (from bottom to top, eventually leading to the result of slowdown and timeout)
Other instructions
If you find that the third line is similar to curl_exec()
, for example: this is usually due to network io taking up time. If a third party must be requested, then. . Bear with it.
[0x00007fb6262136f0] curl_exec() /usr/share/nginx/
Similarly, if there is mysql_query
and the like, it is also caused by sql
slow query
Reference link
php-fpm configuration: https://www.php.net/manual/zh/install.fpm.configuration.php
how-to-read-the-php-slow-request-log: https://serverpilot.io/docs/how-to-read-the-php-slow-request-log/