PHP Error mechanism knowledge Summary, PHP mechanism summary _php Tutorial

Source: Internet
Author: User
Tags php error what php

PHP Error mechanism knowledge Summary, PHP mechanism summary


PHP's error mechanism is also very complex, did a few years of PHP, also did not carefully summed up, now fill this lesson.

Special Note: The PHP version of the article uses 5.5.32

Error level for PHP

First you need to know what PHP errors are. Up to php5.5, a total of 16 error levels

Note: When trying the following code, make sure to open error_log:

E_error

This error is fatal and will show fatal error on the page, and when this error occurs, the program will not be able to carry on.

Error Example:

Note that this level is also triggered if there are uncaught exceptions.

E_warning

This error is just a warning, does not terminate the script, the program will continue, and the error message displayed is warning. For example, include a file that does not exist.

E_notice

This is a little bit more subtle, suggesting that this place should not be written in this way. This is also a run-time error, and the code for this error may not be a problem elsewhere, just a problem in the current context.

For example, the $b variable does not exist, we assign it to another variable

E_parse

This error occurs at compile time, syntax errors are found during compilation, and parsing is not possible.

For example, the following z is not set to a variable.

E_strict

This error was introduced after PHP5, your code can be run, but not PHP's suggested notation.

For example, the function parameter pass + + symbol

E_recoverable_error

This level is actually an error level, but it is expected to be captured, and if not caught by error handling, the performance is the same as E_error.

Often occurs when a parameter defines a type, but when called, the error type is passed in. Its error alert is also more than E_error fatal error in front of a catachable word.


e_deprecated

This error indicates that you have used an older version of the function, and the later version of the function may be disabled or not maintained.

such as Curl's curlopt_postfields use \ @FILENAME to upload the file method

E_core_error, e_core_warning

These two errors are generated by the PHP engine, which occurs during the initialization of PHP.

E_compile_error, e_compile_warning

These two errors are generated by the PHP engine and occur during the compilation process.

E_user_error, E_user_warning, E_user_notice, e_user_deprecated,

These errors are made by the user, and using Trigger_error, this is the equivalent of a hole that gives the user a variety of error types. This is a good way to evade the try catch exception.

E_all

E_strict all error and warning messages that go out.

Error control

There are many configurations and parameters in PHP that can control errors, as well as errors in the log display. First, what do we need to know about the configuration of the error in PHP?

We follow the PHP+PHP-FPM model, will affect the PHP error display is actually two configuration files, one is the PHP itself configuration file php.ini, the other is PHP-FPM configuration file, php-fpm.conf.

Configuration in the php.ini

We are often asked, what is the difference between error_reporting and display_errors? The two functions are completely different.

PHP defaults to the log and standard output (if the FPM mode standard output is the page)

The error_reporting parameter is the error level. The level that represents what you should trigger the error. If we tell PHP that all error levels do not need to trigger an error, then neither the log nor the page will show this error, which would be equivalent to nothing happening.

Display_errors is to control whether to display error messages in standard output

Log_errors is the control of whether to log error messages.

Error_log is the location where the error log is displayed, which is often rewritten in php-fpm, so it is often found that the CLI and FPM error logs are not in the same file.

Ignore_repeated_errors This tag controls if there is a duplicate log, then only one is logged, such as the following program:

Would have appeared two times notice, but now, will only appear once ...

Track_errors Open will store the last error message in a variable, which may be useful for logging. But I think it's really useless.

Html_errors and Docref_root Two is a very user-friendly configuration, after configuring the two parameters, we return the error message if there is some information in the document, it will become a link form.

Page display:

Allows you to quickly locate where we are wrong. is not very human ~

Configuration in the PHP-FPM

There is also a error_log configuration in the PHP-FPM configuration, which is often confused with the Error_log configuration in php.ini. But the things they record are not the same,

PHP-FPM's error_log logs only the PHP-FPM itself, such as FPM startup and shutdown.

The Error_log in php.ini is the error log that records the PHP program itself.

Then in PHP-FPM to overwrite the error_log configuration in the php.ini, you need to use the following functions:

Php_flag
Php_value
Php_admin_flag
Php_admin_value

The two functions of the four functions Admin show that after this variable is set up, you cannot use Ini_set in your code to reassign the variable to another value. Php_flag/value is still based on the ini_set in the PHP code.

Slowlog is the FPM record, you can use the Request_slowlog_timeout setting to determine the length of the slow log.

Summarize

What we often confuse is log issues, and why some levels of logging are not recorded in the log. The main thing is to see Error_log,display_errors, log_errors These three configurations, just look at the configuration, we also have to pay attention to distinguish php.ini inside the configuration is what, Php-fpm.ini inside the configuration is what.

Well, I think to understand these configurations, basically there is no PHP log can not record the WTF problem.

About the PHP error mechanism knowledge summary of the small series to introduce to you here, I hope to help you!

Articles you may be interested in:

    • Analysis of error handling and exception handling mechanism in PHP
    • PHP error, exception handling mechanism (supplemental)
    • PHP error handling mechanism

http://www.bkjia.com/PHPjc/1113699.html www.bkjia.com true http://www.bkjia.com/PHPjc/1113699.html techarticle PHP Error mechanism knowledge Summary, PHP mechanism summary PHP error mechanism is also very complex, did a few years of PHP, did not carefully summed up, now fill this lesson. Special Note: Article ...

  • 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.