简体   繁体   English

关闭PHP中的错误报告(主要值与本地值)

[英]Turn off error reporting in PHP (Master vs local value)

I have tried turning off error reporting in my code using 我尝试使用以下方式关闭代码中的错误报告

error_reporting(0);
@ini_set('display_errors', 0);

and also by editing both the .htaccess files in both the root and frontend folders (separately). 以及通过分别编辑根文件夹和前端文件夹中的.htaccess文件。

Editing the .htaccess to include code such as 编辑.htaccess以包含诸如以下代码

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/logs/PHP_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0

Produces a 500 error. 产生500错误。 Editing the .htaccess is otherwise allowed on this server, 否则,此服务器上允许编辑.htaccess,

The description of the error is 错误的描述是

Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration 无效命令'php_flag',可能是服务器配置中未包含的模块拼写错误或定义了

So it apparently doesn't like me adding this type of code in the .htaccess due to some underlying configuration. 因此,由于某些基础配置,它显然不喜欢我在.htaccess中添加此类代码。

Looking at phpinfo() it says that the local value of error reporting is "off" (presumably caused by error_reporting(0)), but crucially the master value is "on". 查看phpinfo(),它表示错误报告的本地值是“ off”(大概是由error_reporting(0)引起的),但关键是主值是“ on”。

How might the master value be overwritten, or the local value actually win out? 主值将如何被覆盖,或者本地值实际如何获胜? (errors are still reported when local value is "off") (当本地值“关闭”时仍会报告错误)

You should not need the Php directives in .htaccess file. 您不需要.htaccess文件中的Php指令。

The master value for a Php configuration is the value before any Php code is executed. Php配置的主值是执行任何Php代码之前的值。 The local value is the value of the configuration at the time the phpinfo() function is called. 本地值是调用phpinfo()函数时的配置值。 See this link: What is the difference between local value and master value 查看此链接: 本地值和主值之间有什么区别

The following code added at the top of your Php file should turn of error reporting: 在您的Php文件顶部添加的以下代码应转为错误报告:

error_reporting(0);
ini_set('display_errors', 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM