preface

As a programmer, the only thing slightly more important than code is log analysis and query. Common logging and setting methods are listed below.

PHP – FPM slow logs

PHP slow logging needs to be set in php-fpm.conf. If you use the source code package, run the following command by default

cp php-fpm.conf.default php-fpm.conf
Copy the code

The default directory for installing PHP via source package compilation should be in

/usr/local/php
Copy the code

If you don’t know or don’t know the specific directory where PHP is installed, you can use it

find / -name php-fpm.conf
Copy the code

or

php -i | grep Path
------------------------------------------
[root@xxxx etc]# php -i | grep Path
Configuration File (php.ini) Path => /usr/local/php/etc
XPath Support => enabled
Path to sendmail => /usr/sbin/sendmail -t -i
[root@xxxx etc]#
Copy the code

Enable slow log query

The old version is set in php-fpm.conf (actually I forget which version), the php7.x version of the source package after compilation requires www.conf to modify the slow query configuration

vim /usr/local/php/etc/php-fpm.d/www.conf
Copy the code

If you can’t find it in php-fpm.conf, go to its sibling php-fpm.d.

; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set ; slowlog = log/$pool.log.slow ; 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 = 0Copy the code

  • Slowlog Sets the directory for generating slow query logs
  • Request_slowlog_timeout Specifies the standard time of slow slowquery. (If this parameter is enabled, slow query logs are enabled.) The value is set in seconds.

Php-error Indicates error logs

PHP errors are not allowed in production, and even if they are blank or 500, log collection is very important in production.

Enabling error logging

Typically, PHP error logging is configured in the php.ini file

/usr/local/php/etc/php.ini --------------------------- error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors = Off log_errors = On ; Log errors to specified file. PHP's default behavior is to leave this value ; empty. ; http://php.net/error-log ; Example: ; error_log = php_errors.log ; Log errors to syslog (Event Log on Windows). ; error_log = syslogCopy the code

  • Error_log Indicates the directory where error logs are generated
  • Error_reporting Indicates the error level of the production environment
  • Display_errors does not display errors on the page
  • Log_errors Enables error logging

The end result is

error_log = /var/log/php_error.log
display_errors = Off
error_reporting = E_ALL
log_errors = On
Copy the code

I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, Redis, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc. Many knowledge points can be free to share with you