How to analyze slow? Log of PHP FPM?

The article was forwarded from the professional Larvel developer community, the original link: https://learnku.com/laravel/t...

Improve the stability of Drupal or WordPress websites by using PHP slow logs and PHP FPM error logs to locate serious performance problems.

One of the important ways to find problems with your Web site is to check your PHP logs. This article will guide you on how to use PHP slow log and PHP FPM error log to find performance problems and website errors.

Before the start

Confirm that you have:

  • A SFTP command line tool (CLI)
  • Understanding PHP usage

Download PHP slow log and PHP FPM error log using SFTP

  1. Add yourself to the site team.
  2. Obtain SFTP connection information from the site's dashboard (test, development, real-time or Multidev) environment.
  3. Open a command line prompt and paste the SFTP connection information.
  4. Enter the log directory, and use the get command to download the PHP slow log to the local machine for analysis.

    > $ sftp -o Port=2222 live.91f33beg-d11b-4020a-0005e0-07ca0f4ce7bz@appserver.live.91f33beg-d11b-4020a-0005e0-07ca0f4ce7bz.drush.in
    > live.91fd3bea-d11b-401a-85e0-0@appserver.live.91f33beg-d11b-4020a-0005e0-07ca0f4ce7bz.drush.in's password:
    > live.91fd3bea-d11b-401a-85e0-0@appserver.live.91f33beg-d11b-4020a-0005e0-07ca0f4ce7bz.drush.in's password:
    > Connected to appserver.live.91f33beg-d11b-4020a-0005e0-07ca0f4ce7bz.drush.in.
    > sftp> cd logs
    > sftp> ls -l
    > -rw-r--r--    1 16193    16193      153146 Dec 15 22:34 newrelic.log
    > -rw-r--r--    1 16193    16193    55123460 Dec 15 22:59 nginx-access.log
    > -rw-r--r--    1 16193    16193     3479688 Dec 09 08:07 nginx-access.log-20141209.gz
    > -rw-r--r--    1 16193    16193     5524355 Dec 10 08:07 nginx-access.log-20141210.gz
    > -rw-r--r--    1 16193    16193     5602638 Dec 11 08:06 nginx-access.log-20141211.gz
    > -rw-r--r--    1 16193    16193     6033991 Dec 12 08:07 nginx-access.log-20141212.gz
    > -rw-r--r--    1 16193    16193     5793730 Dec 13 08:07 nginx-access.log-20141213.gz
    > -rw-r--r--    1 16193    16193     4688934 Dec 14 08:07 nginx-access.log-20141214.gz
    > -rw-r--r--    1 16193    16193     5867636 Dec 15 08:07 nginx-access.log-20141215.gz
    > -rw-r--r--    1 16193    16193        3499 Dec 15 22:46 nginx-error.log
    > -rw-r--r--    1 16193    16193     1126685 Dec 14 08:07 nginx-error.log-20141214
    > -rw-r--r--    1 16193    16193        5017 Dec 15 11:52 php-error.log
    > -rw-------    1 16193    16193      642388 Dec 15 22:55 php-fpm-error.log
    > -rw-------    1 16193    16193     1067358 Dec 12 20:07 php-fpm-error.log-20141212
    > -rw-------    1 16193    16193     7209576 Dec 15 22:55 php-slow.log
    > sftp> get php-slow.log
    > Fetching /srv/bindings/d142301948514750b2ff39988as6f4b9158e5/logs/php-slow.log to php-slow.log
    > /srv/bindings/d142301948514750b2ff39988as6f4b9158e5/logs/php-slow.log 100% 7041KB 370.6KB/s   00:19
    > sftp> get php-fpm-error.log
    > Fetching /srv/bindings/b6126cf3069a4ba5983f3e9eaf35d627/logs/php-fpm-error.log to php-fpm-error.log
    > /srv/bindings/b6126cf3069a4ba5983f3e9eaf35d627/logs/php-fpm-error.log                                                                              100%  717KB 238.9KB/s   00:03
    > sftp> exit
    > $
    

Analyzing the slow query log of PHP

You can use the grep command to quickly locate the number of times a function call is recorded. The more times it is recorded, the higher the priority of optimization is.

> $ grep -o 'stream_wrappers.inc' php-slow.log | wc -l
56
> $ grep -o 'page.tpl' php-slow.log | wc -l
48
> $ grep -o '.tpl' php-slow.log | wc -l
73
> $ grep -o 'tdm_'.*.'module' php-slow.log | wc -l
1995
> $

Analyze PHP FPM error log

You can also analyze the error log location problem of PHP FPM generated by NGINX, such as PHP worker execution timeout and end. Each PHP worker has a unique process ID, which will also be recorded in the PHP slow log. So you can associate the PHP FPM error log with the PHP error log. In the following example, the worker ID is 119057.

// PHP FPM error log content
[16-Dec-2014 14:54:21] NOTICE: [pool www] child 119057 exited with code 0 after 323.614265 seconds from start

// PHP slow log content
[16-Dec-2014 03:13:50]  [pool www] pid 119057
script_filename = /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/index.php
[0x0000000003160c28] drupal_substr() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/sites/all/modules/contrib/cdn/cdn.module:37
[0x000000000315f820] cdn_file_url_alter() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/module.inc:1101
[0x000000000315f498] drupal_alter() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/file.inc:375
[0x000000000315f148] file_create_url() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/sites/all/modules/contrib/cdn/cdn.basic.css.inc:155
[0x00007fff92553cb0] _cdn_build_css_path() unknown:0
[0x000000000315e160] preg_replace_callback() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/sites/all/modules/contrib/cdn/cdn.basic.css.inc:95
[0x000000000315d7e8] _cdn_build_css_cache() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/sites/all/modules/contrib/cdn/cdn.basic.css.inc:33
[0x000000000315bce0] _cdn_aggregate_css() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:3391
[0x000000000315ad98] drupal_pre_render_styles() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:5931
[0x000000000315a568] drupal_render() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:3127
[0x000000000315a030] drupal_get_css() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/theme.inc:2707
[0x0000000003158210] template_process_html() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/theme.inc:1125
[0x00000000031572c0] theme() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:5967
[0x0000000003156da0] drupal_render() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:5814
[0x0000000003155c68] drupal_render_page() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:2701
[0x00000000031558b0] drupal_deliver_html_page() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/common.inc:2589
[0x0000000003155200] drupal_deliver_page() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/includes/menu.inc:532
[0x0000000003155020] menu_execute_active_handler() /srv/bindings/d9e7c7e384eb453f8ac80cee5d4d791bad2wqq34d/code/index.php:21

By using these methods and files to locate PHP errors and performance problems, the stability of the website can be greatly improved.

Tags: PHP Nginx sftp Laravel

Posted on Mon, 21 Oct 2019 22:18:10 -0400 by clanstyles