1. php Slow Script Log
- Intermittent 502, is caused by the backend php-fpm is not available, the intermittent 5,021-like is due to the PHP-FPM process restart.
An intermittent 502 error occurs when the number of PHP-FPM in a configuration exceeds the number of child processes, and if max_requests is set in the configuration, there will be a 502 error over the number, and max_requests settings It is to prevent unsafe third-party library script memory leaks , of course, you write your own script has a deadlock , there will also be 502 phenomenon.
If you find that MySQL load is not high, but the number of php-fpm processes and memory consumption is too high, congratulations, most of the situation is because the script has a deadlock.
2. Now that you have found the problem with PHP, how do you locate the PHP script?
To open the PHP slow query log:
$ sudo vi /usr/loal/php/etc/php-fpm.conf
; 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 default request_slowlog_timeout is 0,php the slow script log is off, so set to n greater than 0, which means that scripts that execute more than n are logged into the slowlog.
Then monitor the site when there is a problem when viewing the next Slowlog can find slow script, the script to check processing.
3.2, MySQL slow query log
The MySQL slow query log is useful for tracking problematic queries and can analyze the resource-intensive SQL statements in the current program, so how do I turn on slow query logging for MySQL?
In fact, the slow query log to open MySQL is very simple, only need to in the MySQL configuration file (Windows system is My.ini,linux system is my.cnf) of the [mysqld] under the following code:
log-slow-queries=/var/lib/mysql/slowquery.log
long_query_time=2
The 2 in long_query_time=2 indicates that the query is not logged for more than two seconds.
If the log content is many, with the eye one by one to see will be exhausted, MySQL comes with the tool of analysis, using the following methods:
$ cd /usr/local/mysql/bin
$ mysqldumpslow –help
-s,是order的顺序,主要有c,t,l,r和ac,at,al,ar,分别是按照query次数,时间,lock的时间和返回的记录数来排序,前面加了a的时倒叙
-t,是top n的意思,即为返回前面多少条的数据
-g,后边可以写一个正则匹配模式,大小写不敏感的
$ mysqldumpslow -s c -t 20 host-slow.log #访问次数最多的20个sql语句
$ mysqldumpslow -s r -t 20 host-slow.log #返回记录集最多的20个sql
$ mysqldumpslow -t 10 -s t -g “left join” host-slow.log #按照时间返回前10条里面含有左连接的sql语句
MySQL Slow query log query manual
PHP slow script log and MySQL slow query log (GO)