Describes how to obtain PHP error logs and how to obtain php logs.

Source: Internet
Author: User
Tags php error

Describes how to obtain PHP error logs and how to obtain php logs.

There are many methods to obtain error logs in PHP. I will give you a brief introduction to how to solve these problems. The following code will show you how to help you.

<? Phperror_reporting (0); register_shutdown_function ($ err = 'my _ error_handler ') OR set_error_handler ($ err, E_ALL); // register two functions at the same time. // function parameter error $ original = unserialize (array (423142,4254234); // do not divide echo 1/0 on 0; // nonexistent array index echo $ _ GET ['a']; // nonexistent constant PHP_E; // nonexistent variable echo $ var; // function parameter error strlen (array (2434); // function parameter error md5 (array (1); // user-defined error trigger_error ('safdds ', e_USER_NOTICE); // php interrupt for nonexistent functions // tes (); // php interrupt for nonexistent Methods $ ts = new afsd (); function my_error_handler ($ errno = 0, $ errstr = 0, $ errfile = 0, $ errline = 0) {if ($ errno & $ errfile) {if (true) {$ earr = array (); $ earr ['type'] = $ errno; $ earr ['message'] = $ errstr; $ earr ['file'] = $ errfile; $ earr ['line'] = $ errline;} else {$ earr = error_get_last ();} echo '<pre>'; print_r ($ earr ); return array ();}

For php errors, we must be clear about the types, when to trigger, and what is the returned value.

If you do not distinguish between warning, error, suggestion, and prompt types, we can understand that there are two php error types:

One is force interrupt program errors, such as errors, method does not exist, etc. Insufficient memory, timeout

A non-disruptive error, such as a warning.

The register_shutdown_function function is used to obtain an interrupt program error. Register a memory function and obtain the error information. This method can only obtain the first error row. For example, when multiple non-existing functions exist, it can only get the first error. this is also advantageous. If you fix one, it will be moved to the next one.

Non-disruptive error. If register_shutdown_function is used, it will become difficult to operate. Only the first prompt or warning can be obtained. In this case, we need set_error_handler, and each time an error level constants is triggered, you can call the error function once to obtain the error log. however, this function will undertake the error_get_last function, so you will find that the returned error_get_last is null, all of which are passed in by parameters.

Using the two functions together, we can get the 99% error of the program. This is a lighter in the snow for the php program.

Run the preceding example.

Combine code and text to sort out the methods for obtaining error logs in PHP, hoping to help you solve such problems in your future work.

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.