This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14157|Reply: 0

[Web] Enable slow log configuration in nginx php-fpm (to detect slow-executing PHP scripts)

[Copy link]
Posted on 10/23/2014 11:49:24 PM | | |

Many webmasters are troubled by 500,502 issues after switching to nginx+php-fpm. When nginx receives the above error code, it can be determined that there is some kind of problem with the backend php-fpm parsing php, such as execution error or execution timeout.

php-fpm.conf has a parameter request_slowlog_timeout described like this

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

When request_slowlog_timeout is set to a specific second request_slowlog_timeout =5, it means that if a script is executed for more than 5 seconds, the script will be recorded in the slow log file


request_slowlog_timeout =0 means that slow log output is turned off.

The slow log file location is in the log folder in the php installation directory by default, and you can specify it by modifying the slowlog = log/$pool.log.slow parameter.

php-fpm slow log example, the slow log will record the process number, script name, specific file which line of code, which function is too long to execute.

  1. [21-Nov-2013 14:30:38] [pool www] pid 11877
  2. script_filename = /usr/local/lnmp/nginx/html/www.quancha.cn/www/fyzb.php
  3. [0xb70fb88c] file_get_contents() /usr/local/lnmp/nginx/html/www.quancha.cn/www/fyzb.php:2
  4. [21-Nov-2013 14:15:23] ERROR: [pool www] 'slowlog' must be specified for use with 'request_slowlog_timeout'
Copy code

request_slowlog_timeout and slowlog need to be set at the same time, and you need to turn on slowlog at the same time as turning on the request_slowlog_timeout

  1. [21-Nov-2013 14:16:27] ERROR: Unable to create or open slowlog(/usr/local/lnmp/php/log/www.log.slow): No such file or directory (2)
Copy code

Slow log paths need to be created manually


Specific steps to enable php-fpm slow logging:

  1. cd /usr/local/lnmp/php

  2. vi etc/php-fpm.conf
  3. 去掉request_slowlog_timeout 、slowlog的前缀分号';',设置request_slowlog_timeout =5;
  4. :wq
  5. 保存退出
  6. 创建慢日志目录
  7. mkdir log
  8. 重启php-fpm
  9. kill -INT `cat var/run/php-fpm.pid
  10. sbin/php-fpm
Copy code






Previous:When posting, the php-fpm process instantly reaches 99% of the CPU, fault analysis
Next:Chopstick Brothers' Divine Comedy "Little Apple" Hi you, there is a beautiful girl
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com