PHP slow script log and Mysql slow query log

Source: Internet
Author: User
Tags mysql slow query log
1, PHP slow script log intermittent 502, is caused by the failure of the back-end PHP-FPM, intermittent 502 is generally considered to be caused by the restart of the PHP-FPM process. An intermittent 502 error occurs when the number of child processes in the PHP-FPM exceeds the number in the configuration, and if max_requests is set in the configuration, a 502 error occurs when the number is exceeded.

1, PHP slow script log intermittent 502, is caused by the failure of the back-end PHP-FPM, intermittent 502 is generally considered to be caused by the restart of the PHP-FPM process. An intermittent 502 error occurs when the number of child processes in the PHP-FPM exceeds the number in the configuration, and if max_requests is set in the configuration, a 502 error occurs when the number is exceeded.

1. PHP slow script log
  • Intermittent 502 is caused by backend PHP-FPM unavailability, intermittent 502 is generally considered to be caused by the restart of the PHP-FPM process.
  • An intermittent 502 error occurs when the number of child processes in the PHP-FPM exceeds the number in the configuration ifMax_requestsIf the number is exceeded, the error 502 will also occur. The setting of max_requests is to prevent insecure third-party library scripts.Memory leakageOf course, your own scripts exist.DeadlockThen, there will also be a 502 phenomenon.

  • If you find that the mysql load is not high, but the php-fpm process count and memory usage are too high, congratulations, most of the time it is because the script has a deadlock.

Since it is a php issue, how can I locate the php script?

Enable php slow query log:

$ sudo vi /usr/loal/php/etc/php-fpm.conf; Default Value: 0request_slowlog_timeout = 1s; The log file for slow requests; Default Value: /usr/local/php/log/php-fpm.log.slowslowlog = /usr/local/php/log/php-fpm.log.slow

The default request_slowlog_timeout value is 0, and the slow script log of php is disabled. Therefore, if it is set to n greater than 0, the script whose execution time exceeds n will be recorded in the slowlog.
Check the slowlog to find the slow script and check the script.

2. Mysql slow query log

Mysql slow query logs are very useful for queries with tracing problems. We can analyze the resource-consuming SQL statements in the current program. How can we open mysql slow query log records?

In fact, it is very easy to open the slow query log of mysql, just in the mysql configuration file (windows system is my. ini, linux is my. the following code is added to [mysqld] of cnf:

log-slow-queries=/var/lib/mysql/slowquery.log long_query_time=2 

2 In long_query_time = 2 indicates that the query takes more than two seconds to record.
If there is a lot of log Content, it will be exhausting to look at it with one eye. mysql comes with an analysis tool, which is used as follows:

$ Cd/usr/local/mysql/bin $ mysqldumpslow-help-s is the order, mainly including c, t, l, r and ac, at, al, ar, they are sorted by the number of queries, time, lock time, and number of returned records. When a is added, the reverse-t indicates top n, that is, the number of data records in the previous row-g is returned, and a regular expression matching mode can be written later, case Insensitive $ mysqldumpslow-s c-t 20 host-slow.log #20 SQL statements with the most accesses $ mysqldumpslow-s r-t 20 host-slow.log #20 SQL statements with the most returned record set $ mysqldumpslow-t 10-s t-g "left join" host-slow.log # Return the first 10 SQL statements containing the left join by Time

Mysql slow query log query manual

Original article address: PHP slow script log and Mysql slow query log. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.