Two kinds of log instance analysis that php programmer must know

Time:2020-10-29

This article describes two kinds of logs that PHP programmers must know. For your reference, the details are as follows:

preface

As a programmer, a little more important than code code is log analysis and query. The following is a list of common logs and setting methods.

PHP FPM slow log

PHP slow log needs to be in PHP- fpm.conf If you use the source package to install the default, execute the following command


cp php-fpm.conf.default php-fpm.conf

By default, the PHP directory should be in the


/usr/local/php

Directory, if you install through Yum or other methods, do not know or do not know the specific PHP installation directory, you can use


find / -name php-fpm.conf

or


php -i | grep Path
------------------------------------------
[[email protected] 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
[[email protected] etc]#

Open slow query log

The old version was in PHP- fpm.conf Setting (actually I forgot which version I forgot), php7. X source package needs to be compiled www.conf Modify slow query configuration


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

But the configuration items are the same if you are in PHP- fpm.conf If you can’t find it, go to the same level directory 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 = 0
  • Slowlog sets the generation directory of slow query log
  • request_ slowlog_ Timeout sets the standard time of slow query (opening this configuration is equivalent to opening the slow query log). The configuration is in seconds. Generally, it is set to 3S.

PHP error error log

In the production environment, PHP is not allowed to report errors, even if the error is white screen or 500, so the log collection in the production environment is very important.

Open error log

Generally, the configuration of PHP error log is in the php.ini In the 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 = syslog
  • error_ Log error log generation directory
  • error_ Reporting production environment error level should be fully open
  • display_ Errors does not display errors on the page
  • log_ Open error log

The end result is


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

More interested readers about PHP related content can view the special topics of this website: summary of PHP log operation skills, summary of PHP file operation, complete of PHP array operation skills, introduction course of PHP basic syntax, summary of PHP string usage, introduction course of PHP + MySQL database operation and summary of common database operation skills of PHP

I hope this article will help you with PHP programming.

Recommended Today

MVC and Vue

MVC and Vue This article was written on July 27, 2020 The first question is: is Vue an MVC or an MVVM framework? Wikipedia tells us: MVVM is a variant of PM, and PM is a variant of MVC. So to a certain extent, whether Vue is MVC or MVVM or not, its ideological direction […]