When developing a website using PHP, if some PHP dynamic pages are very slow to access after launch, we can analyze the bottleneck of the website through php-fpm slow logs.
php-fpm slowlog setting allows us to see which php processes are too slow and cause website problems.
First, check all processes via the top -c command to see the configuration file address loaded by php-fpm, as shown in the figure below:
FPM configuration
parameter: -p, dynamically modify --prefix in the command line
include=etc/php-fpm.d/*.conf to contain one or more files if glob(3) exists (glob() function returns a filename or directory that matches the specified pattern)
php-fpm loads a sub-configuration file, $pool variable can be used in any directive, and it will replace the corresponding process pool name. For example: here[www]
Turn on slow logs
enter/usr/local/etc/php-fpm.dSub-configuration file, find www.conf (according to your actual situation), PHP 5.3.3 and later versions are set as follows:
; 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 ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 10s Note: request_terminate_timeout Terminate a process that has been running for too long directly
request_slowlog_timeout Write files that are too slow to execute to the log
From now on, you can optimize the program files according to the slow execution log /usr/local/php/log/php-fpm.log.slow!
|