Home > Backend Development > PHP Tutorial > Summary and performance analysis of turning off error prompts in php_PHP tutorial

Summary and performance analysis of turning off error prompts in php_PHP tutorial

WBOY
Release: 2016-07-13 16:56:23
Original
794 people have browsed it

This article introduces some PHP error prompt methods in PHP development. Friends in need can refer to this article.

1. Close the notice error prompt

1. Change error_reporting in the php.ini file

changed to:

The code is as follows
 代码如下 复制代码

error_reporting=E_ALL & ~E_NOTICE

Copy code

error_reporting=E_ALL & ~E_NOTICE

 代码如下 复制代码

error_reporting(E_ALL^E_NOTICE);

2. If you cannot operate the php.ini file, you can use the following method

Add the following code to the page where you want to disable notice error prompts:

The code is as follows Copy code

 代码如下 复制代码

找到display_errors = On 修改为 display_errors = off

error_reporting(E_ALL^E_NOTICE);


This way there will be no prompts when errors occur
 代码如下 复制代码

//禁用错误报告
error_reporting(0);
//报告运行时错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//报告所有错误
error_reporting(E_ALL);
?>


 

2. Close all error prompts

php.ini

Open the php.ini file in the PHP installation directory

The code is as follows
Copy code

Find display_errors = On and change it to display_errors = off

Note: If you have copied the PHP.ini file to the windows directory, you must also change display_errors = On in c:windows/php.ini to display_errors = off

php program is opened

The code is as follows Copy code


//Disable error reporting

error_reporting(0);

//Report runtime errors

error_reporting(E_ERROR | E_WARNING | E_PARSE);

//Report all errors
error_reporting(E_ALL);

?>

Turning off error prompts in terms of performance will increase the server performance load a lot

Test 1: Test the performance of uninitialized variables and initialized variables in 10000000 loops with error display turned off The loop code with initialized variables is as follows: The loop code with uninitialized variables is as follows:
Test results:
Initialization: 5.28 seconds average Uninitialized: 17.2 seconds average Performance gap: 3.25 times Average timetable: We can see that turning off PHP error output will not turn off the PHP kernel's error processing. If there are a large number of Notice-level errors in the code, it will still reduce the performance of the PHP program. http://www.bkjia.com/PHPjc/631596.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631596.htmlTechArticleThis article introduces some PHP closing error prompt methods in PHP development. Friends in need can refer to this article. . 1. Close the notice error prompt 1. Change error_re... in the php.ini file
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template