PHP Auto Capture Page 500 error example

Source: Internet
Author: User
Tags ini php error

It is not difficult to get the error message when the page is blank when a fatal error occurs in the program. The main use of two functions:

Error_get_last () Gets the last occurrence of the error message: The structure is as follows:

The code is as follows

[Type] => 8
[Message] => Undefined variable:
[File] => c:wwwindex.php
[Line] => 2

Register_shutdown_function () registers a callback function when the script stops executing

With these two functions you can monitor for fatal errors:

  code is as follows &nbs P;

error_reporting (e_all);//e_all
Function Cache_shut Down_error () {
    $_error = Error_get_last ();
    if ($_ Error && In_array ($_error[' type '), Array (1, 4,, 256, 4096, E_all)) {
   &nbs p;    Echo ' <font color=red> Your code is wrong:</font></br> ';
        Echo Fatal error: '. $_error[' message ']. ' </br> ';
        echo ' files: '. $_error[' file '. ' </br> ';
        Echo ' in the '. $_error[' line ']. ' Line </br> ';
register_shutdown_function ("Cache_shutdown_error");

Sequential attached local server test method

Here are three ways to display a PHP error message.

One: php.ini configuration

There are two configuration variables associated with this in the php.ini configuration. The following are the two variables and their default values:

The code is as follows

Display_errors = Off
error_reporting = E_all & ~e_notice

The purpose of the display_errors variable is obvious-it tells PHP if it shows an error. The default value is off. Now our goal is to display error prompts, then:

The code is as follows

Display_errors = On

E_all, this setting displays all information from bad coding practices to harmless hints to errors. E_all is a bit too thin for the development process because it also shows hints that the variable is not initialized, which is a feature of PHP's "advanced". Fortunately, the default value of Error_reporting is "E_all & ~e_notice", so that only errors and bad coding are seen, and no adverse prompts are displayed.

After modifying the php.ini, you need to restart Apache, so you can take effect in Apache, but you don't need this step if you only test the program at the command line.

Configuring the PHP Program

The code is as follows

disabling error Reporting
error_reporting (0);
Report Run-time Errors
Error_reporting (E_error | e_warning | E_parse);
Report All Errors
Error_reporting (E_all);

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.