当我需要错误报告显示控制时,我最好使用哪种方法?

时间:2022-12-04 20:30:00

I want to manage error message display control,

我想管理错误信息显示控制,

and I Googled for a while,

我用谷歌搜索了一会儿,

and I found that there are several ways to do it.

我发现有几种方法可以做到这一点。

which method do I have to choose?

我必须选择哪种方法?

The thing I want to do is that

我想做的就是那个

I don't want to PHP
shows up any errors on users display,

我不希望PHP显示用户显示的任何错误,

on Production Server.

在Production Server上。

2 个解决方案

#1


Use error_reporting()

On production, disable errors by doing:

在生产时,通过执行以下操作禁用错

error_reporting(0);

Report runtime errors on development like this:

报告运行时错误,如下所示:

error_reporting(E_ERROR | E_WARNING | E_PARSE);

And report all errors like this:

并报告所有错误:

error_reporting(E_ALL);

See the above link for a complete list of report_level constants with detailed descriptions, as well as the manual page:

有关详细说明的report_level常量的完整列表,请参阅上面的链接,以及手册页:

http://us.php.net/manual/en/function.error-reporting.php

#2


It's best to log all errors to a file:

最好将所有错误记录到文件中:

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', '/tmp/php_errors.log');

On unix, you can watch errors using this command:

在unix上,您可以使用以下命令查看错误:

bash$ tail -f /tmp/php_errors.log

Or you can just open the log file in a text editor.

或者您可以在文本编辑器中打开日志文件。

This setup can be used on a production server as well, you can download the php_errors.log file periodically to see if there are any bugs.

此设置也可以在生产服务器上使用,您可以定期下载php_errors.log文件以查看是否存在任何错误。

#1


Use error_reporting()

On production, disable errors by doing:

在生产时,通过执行以下操作禁用错

error_reporting(0);

Report runtime errors on development like this:

报告运行时错误,如下所示:

error_reporting(E_ERROR | E_WARNING | E_PARSE);

And report all errors like this:

并报告所有错误:

error_reporting(E_ALL);

See the above link for a complete list of report_level constants with detailed descriptions, as well as the manual page:

有关详细说明的report_level常量的完整列表,请参阅上面的链接,以及手册页:

http://us.php.net/manual/en/function.error-reporting.php

#2


It's best to log all errors to a file:

最好将所有错误记录到文件中:

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', '/tmp/php_errors.log');

On unix, you can watch errors using this command:

在unix上,您可以使用以下命令查看错误:

bash$ tail -f /tmp/php_errors.log

Or you can just open the log file in a text editor.

或者您可以在文本编辑器中打开日志文件。

This setup can be used on a production server as well, you can download the php_errors.log file periodically to see if there are any bugs.

此设置也可以在生产服务器上使用,您可以定期下载php_errors.log文件以查看是否存在任何错误。