错误记录php - error_reporting(0)没有所需的效果 [英] Error logging php - error_reporting(0) not having desired effect

查看:233
本文介绍了错误记录php - error_reporting(0)没有所需的效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很简单的页面,它提取一个url并解析一些数据。



如果响应是404错误,我已经在我的页面中内置了一些错误处理。



但是,我似乎不能阻止php分发以下错误

 
警告:file_get_contents(http://url-to-retrieve.com/123.html)[function.file-get-contents]:无法打开流:HTTP请求失败! HTTP / 1.1 404在/ var / www / html / maickl / procs / get.php on line 91

我开始使用

 
error_reporting(0)

关于为什么会发生这种情况的任何建议,为什么这些错误不被抑制

解决方案

使用 error_reporting( 0); shoud禁用错误报告,这意味着你不应该得到那个错误 - 你确定没有重新启用某个地方吗?





但实际上你可能正在寻找的不是要更改 error_reporting ,但要禁用 display_errors ,可以使用这样一些代码:

  ini_set('display_errors','Off'); 

有了这个:




  • 错误/警告不会显示在您的网站上,对于最终用户来说,这是不错的(不能显示技术错误)

  • error_reporting 未被禁用,这意味着错误仍然可以记录 - 请参阅 log_errors error_log


I've got a pretty simple page which fetches a url and parse some data.

I have built into my page some error handling in the event that the response is a 404 error.

However, I can't seem to stop php from spitting out the following errors

 Warning: file_get_contents(http://url-to-retrieve.com/123.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/html/maickl/procs/get.php on line 84

Notice: Undefined offset: 0 in /var/www/html/maickl/procs/get.php on line 91

I start the page with

error_reporting(0)

Any suggestions as to why this is happening, why these errors are not being suppressed (it seems to be only on this page), and what I can do about it?

解决方案

Using error_reporting(0); shoud disable error reporting, which means you should not get that error -- are you sure it's not re-enabled somewhere ?


But what you are probably looking for, actually, is not to change error_reporting, but to disable display_errors, which can be done using some code like this one :

ini_set('display_errors', 'Off');

With this :

  • errors / warnings will not be displayed on your website, which is nice for end-users (technical errors should never be displayed)
  • but error_reporting is not disabled, which means errors can/will still be logged -- see log_errors and error_log.

这篇关于错误记录php - error_reporting(0)没有所需的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆