Home >Backend Development >PHP Tutorial >How to automatically get errors and exceptions in PHP?

How to automatically get errors and exceptions in PHP?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-08-08 09:06:50888browse

In an online production environment, programs will inevitably encounter errors and exceptions.
We will not find most of these errors and exceptions, so how to automatically obtain these errors and exceptions?
That is, as long as the program encounters errors and exceptions, it will write these errors and exceptions to the Log for recording?
Thank you!

Reply content:

In an online production environment, programs will inevitably encounter errors and exceptions.
We will not find most of these errors and exceptions, so how to automatically obtain these errors and exceptions?
That is, as long as the program encounters errors and exceptions, it will write these errors and exceptions to the Log for recording?
Thank you!

This requires configuring PHP

  • log_errors=On

  • error_log=Log path
    PHP will automatically write to the log when an error occurs.

Define functions, related as follows

  • set_error_handler: Set user-defined error handling function

  • set_exception_handler: Set user-defined exception handling function

The two functions set_exception_handler and set_error_handler can handle uncaught exceptions, then analyze and classify the exception information and write it to the log

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn